-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
📚 Subject area/topic
Endpoints
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/endpoints/
📋 Description of content that is out-of-date or incorrect
- Update code snippets using
APIRoute
Erika was suggesting on Discord:
export const GET: APIRoute = async ({ params, request }) => {...}
should use satisfies instead
I'm not entirely sure why. I tried both but I don't see any differences... Maybe type inference in some cases?
- Misleading wording regarding
props
In params and Dynamic routing, we say:
but because the endpoint is a function and not a component, props aren’t supported.
In static mode, we can share props
through the APIContext
object using getStaticPaths
. So, I think this is not entirely correct and could be confusing. Here's a small repro using a tweaked version of the code snippet we show above this sentence: https://stackblitz.com/edit/astro-endpoints-dynamic-routing?file=src%2Fpages%2Fapi%2F[id].json.ts,src%2Fpages%2Findex.astro&on=stackblitz
But, yeah, I guess we can't do that with on-demand rendered endpoints. So we might need to precise this only applies to on-demand mode.
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
By clicking on the links, the console should log:
1 Chris
15:22:37 [200] /api/1.json 2ms
15:22:38 [200] / 27ms
2 Yan
15:22:39 [200] /api/2.json 4ms
15:22:39 [200] / 28ms
3 Elian
15:22:40 [200] /api/3.json 5ms
15:22:41 [200] / 18ms
props
can be used with endpoints.