diff --git a/src/content/docs/en/core-concepts/endpoints.mdx b/src/content/docs/en/core-concepts/endpoints.mdx index 1903443a1ae2b..cb2c3f8f1207f 100644 --- a/src/content/docs/en/core-concepts/endpoints.mdx +++ b/src/content/docs/en/core-concepts/endpoints.mdx @@ -49,7 +49,6 @@ export const get: APIRoute = async function get ({params, request}) { ... ``` - ### `params` and Dynamic routing Endpoints support the same [dynamic routing](/en/core-concepts/routing/#dynamic-routes) features that pages do. Name your file with a bracketed parameter name and export a [`getStaticPaths()` function](/en/reference/api-reference/#getstaticpaths). Then, you can access the parameter using the `params` property passed to the endpoint function: @@ -127,8 +126,20 @@ export async function get({ params }) { }); } ``` + This will respond to any request that matches the dynamic route. For example, if we navigate to `/helmet.json`, `params.id` will be set to `helmet`. If `helmet` exists in the mock product database, the endpoint will use create a `Response` object to respond with JSON and return a successful [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/API/Response/status). If not, it will use a `Response` object to respond with a `404`. +In SSR mode, certain providers require the `Content-Type` header to return an image. In this case, use a `Response` object to specify a `headers` property. For example, to produce a binary `.png` image: + +```ts title="src/pages/astro-logo.png.ts" +export async function get({ params, request }) { + const response = await fetch("https://docs.astro.build/assets/full-logo-light.png"); + const buffer = Buffer.from(await response.arrayBuffer()); + return new Response(buffer, { + headers: { "Content-Type": "image/png" }, + }); +} +``` ### HTTP methods In addition to the `get` function, you can export a function with the name of any [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). When a request comes in, Astro will check the method and call the corresponding function.