Let's Play with the DEV API

This is a little snippet used in one of my blog posts to illustrate how to work with the dev.to API.

Let's Play with the DEV API

This is a little snippet used in one of my blog posts to illustrate how to work with the dev.to API.

/**
 * Fetch my 5 latest published articles from dev.to
 *
 * ℹ️ We are doing this on the server-side because authenticated
 * endpoints are CORS disabled...meaning we cannot make them from
 * the browser.
 */
const res = await fetch('https://dev.to/api/articles/me/published?per_page=5', {
    headers: {
        /**
         * ℹ️ This is my secret API key. It's been stored in a .env file
         * and imported here. This is a server-side file, so it's safe to
         * store it here.
         */
        'api-key': DEV_TO_API_KEY,
    },
});

articles = await res.json() as IBlogPost[];

return { articles };
    

My Personal Articles on dev.to

Start with a Gravel Road: Why MVPs Beat 12‑Lane Highways
Productivity Unlocked: Your Guide to Daily Inbox Processing
The Hallmark of Great Developers: Writing Simple Code
Ditch the Clutter: Why You Need an Inbox for Your Brain
Embracing Change: The Real Skill Every Software Engineer Needs
/**
 * Fetches the 5 most recent featured articles from the DEV API
 *
 * ℹ️ This is an open endpoint, meaning it does not require an API key.
 * And since dev.to only disables CORS for authenticated endpoints, we
 * are able to make this request from the browser.
 */
async function fetchFeaturedArticles() {
    const res = await fetch('https://dev.to/api/articles?per_page=5');

    featuredArticles = await res.json();
}
        

Featured Articles From dev.to