Building the API Layer
Instead of scattered fetch calls, we'll create a dedicated service layer to handle all requests to WordPress.
const API_URL = process.env.WORDPRESS_API_URL;
export async function getPosts(perPage = 10) {
const res = await fetch(`${API_URL}/posts?per_page=${perPage}&_embed`);
return res.json();
}