DEV Community

Weerasak Chongnguluam
Weerasak Chongnguluam

Posted on

4

ใช้ Dev.to API ถึงข้อมูลของบทความที่เขียนออกมา

เว็บ Dev.to ที่เขียนอยู่นี้มี API ให้ใช้ด้วย ตัวอย่างเช่นถ้าเราอยากลิสต์บทความของ user คนไหนออกมาดูก็เรียก http GET ที่ endpoint นี้ แล้วใส่ query string username กับกำหนดชื่อ username ที่ต้องการลิสต์บทความ

https://dev.to/api/articles?username=iporsut
Enter fullscreen mode Exit fullscreen mode

Alt Text

ซึ่งปกติจะได้ 30 บทความล่าสุด แต่ตัว API support pagination ด้วยก็ใส่ option ดึง page ต่อไปมาได้

ทีนี้ถ้าอยากดูข้อมูลเฉพาะของบทความใดๆ ก็เรียก GET ไปที่ endpoint เดิม แต่ใส่ path param เป็น ID ของบทความที่ต้องการ แบบนี้

https://dev.to/api/articles/719722
Enter fullscreen mode Exit fullscreen mode

ซึ่งก็จะมีข้อมูลของบทความหมายเลข 719722 ออกมาซึ่งรวมทั้ง HTML ของหน้าบทความนี้ด้วย

Alt Text

นอกจากนั้นยังมี API อื่นๆอีกลองเราไปดูได้ที่นี่ครับ https://docs.forem.com/api/

มีประโยชน์มากๆเพราะเราสามารถเขียนบทความที่ dev.to แล้วไปสร้าง page ของเราเองที่ดึงข้อมูลจาก dev.to ไปแสดงเพื่อ custom การแสดงผลเองได้ด้วย

ขอฝาก Buy Me a Coffee

สำหรับท่านใดที่อ่านแล้วชอบโพสต์ต่างๆของผมที่นี่ ต้องการสนับสนุนค่ากาแฟเล็กๆน้อยๆ สามารถสนับสนุนผมได้ผ่านทาง Buy Me a Coffee คลิ๊กที่รูปด้านล่างนี้ได้เลยครับ

Buy Me A Coffee

Sentry image

Make it make sense

Only get the information you need to fix your code that’s broken with Sentry.

Start debugging →

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay