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" },
});
More islands, endpoints and deployment commands
- Add an interactive component
- Read environment variables
- Render on the server
- Render a page on demand
- Configure the site
All islands, endpoints and deployment commands · Astro cheatsheet