DEV Community

Discussion on: How to use the dev.to API!

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚𝐥𝐢𝐞 𝐝𝐞 𝐖𝐞𝐞𝐫𝐝 • Edited

Absolutely!

Arrays start from 0, meaning if you want the latest 2, you want to stop when the array key (the index of the array item) reaches 1. So you have 0, and 1. The API automatically orders by newest first, so we just need to tell it when to stop!

In the code above, simply change if ($key == 2){ break; } to if ($key == 1){ break; }

Hope that helps :) but let me know if you have anymore questions, or it doesn't make sense.

Collapse
 
grantdotdev profile image
Grant Riordan

do we know how we can view the documentation for this API, in terms of query params and such. I'd like to filter out any article which has been archived, or is in Draft format. As when i hit the api, it seems it is returning archived posts aswell.