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

How Hard Should You Review This? Ask What It Touches
Where Trust in Automated Review Actually Comes From
Your Team Is Getting Faster at Code Review. Your Seniors are Drowning.
Pair Programming Earned a Lighter Code Review. AI Hasn't.
The Warning That Took My Site Down Was in the Log the Whole Time
/**
 * 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