Astro · Islands, endpoints and deployment

Create an API endpoint

A .ts file in src/pages exports a function per HTTP method.

// src/pages/api/hello.json.ts
export const GET = () =>
  new Response(JSON.stringify({ message: "Hello" }), {
    headers: { "Content-Type": "application/json" },
  });

Official Astro documentation

More islands, endpoints and deployment commands

All islands, endpoints and deployment commands · Astro cheatsheet

Was this page helpful?