DEV Community

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

Collapse
 
chrisshennan profile image
Chris Shennan

I really like these type of posts, small, clean and straight to the point.

Have you considered using file_get_contents instead of cURL? file_get_contents works with URLs and since this is a straight forward GET request (no authentication or API keys required) it would work fine, make the code a little simpler and reduce the function to get the data to 4 lines

$username = "saymontavares";
$url = "https://dev.to/api/articles?username={$username}";
$res = file_get_contents($url);
$res = json_decode($res, true);
Enter fullscreen mode Exit fullscreen mode