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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay