Skip to content

Instantly share code, notes, and snippets.

@robbertvancaem
Created December 9, 2019 08:30
Show Gist options
  • Save robbertvancaem/c4f1367bd830d56ab95e92adcadae281 to your computer and use it in GitHub Desktop.
Save robbertvancaem/c4f1367bd830d56ab95e92adcadae281 to your computer and use it in GitHub Desktop.
dynamic-routing-now-4
// data/posts.js
import axios from 'axios';
export const getPost = async (slug) => {
const response = await axios.get(`https://www.mywordpress.com/wp-json/wp/v2/posts?slug=${slug}`);
if (!response.data.length) {
return {
statusCode: 404,
};
}
return {
statusCode: 200,
post: response.data[0],
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment