Skip to content

Commit

Permalink
Note endpoint return response
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 31, 2022
1 parent a5d2744 commit f111ea7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/pages/en/core-concepts/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ export async function get({ params, request }) {
}
```

You can also type your endpoint functions using the `APIRoute` type:
You can also return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object as long as it's a [successful response](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses) (e.g. status code 200).

```ts title="src/pages/name.json.ts"
export async function get({ params, request }) {
return new Response(
JSON.stringify({ name: "Astro" }),
{
status: 200
}
)
}
```

Endpoint functions can also be typed with the `APIRoute` type:

```ts
import type { APIRoute } from 'astro';
Expand Down

0 comments on commit f111ea7

Please sign in to comment.