Astro
Astro endpoints
Also called API routes.
Astro endpoints is the name for files in src/pages that export HTTP method handlers instead of a page. They answer with JSON, text, or a file.
How it is measured
Name the file with the output extension, such as feed.xml.ts or stats.json.ts, and export GET, POST, or another method that returns a Response. In a static build, a GET endpoint runs once at build and writes a file. With on-demand rendering, it runs on each request.
Verify by requesting the URL and reading the headers. A static endpoint returns the same bytes every time and can be cached hard. An on-demand endpoint can read cookies, query strings, and headers.
Worked example
A bakery's Astro site exposes /menu.json from menu.json.ts. In static mode the file is generated at build, 3.2 KB, and the order widget loads it from the edge in 20 ms. When prices change, the owner has to rebuild.
She switches the endpoint to on-demand so a price edit shows up at once. Now each request runs the handler, and a typo in it returns a 500 to customers instead of failing the build.
How it differs
Astro endpoints return a raw Response from a URL you name. Astro middleware runs before every page or endpoint and can rewrite, redirect, or add data. An endpoint is a destination; middleware is a checkpoint on the way to one.
Common errors
Expecting a POST endpoint to work in a fully static build. Forgetting the file extension in the name. Reading request headers in a static endpoint where they do not exist. Returning an object instead of a Response. Leaving an unprotected on-demand endpoint that writes data.
In practice
Use endpoints for RSS, JSON feeds, sitemaps, and small webhooks. Decide for each whether it can be static. For any that writes data, add an auth check and test with a request that lacks it.