#I have a /api/list.json in my astro project. It of course works great when I load in on the browser

2 messages · Page 1 of 1 (latest)

thin pagodaBOT
#

Hi @worn dagger. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm glad to hear that your API endpoint is working well in the browser! In Astro, endpoints like /api/list.json are a powerful feature that allows you to serve custom data.

Astro supports creating custom endpoints to serve any kind of data, which can be used for generating images, exposing JSON data, or building a full API for your site. These endpoints are defined by creating .js or .ts files in your /pages directory with the appropriate extension.

For example, your endpoint might look something like this:

// src/pages/api/list.json.js or src/pages/api/list.json.ts
export function GET({ params, request }) {
  return new Response(
    JSON.stringify({
      // your data here
    }),
  );
}

In static mode, these endpoints are called at build time to produce static files. If you're using SSR (Server-Side Rendering), they become live server endpoints that are called on request.

If you want to expand your API functionality, you can also create dynamic endpoints using Astro's dynamic routing features.

Is there anything specific you'd like to know about working with API endpoints in Astro?

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: