From 91bd041a0c30de7d63d316f187063fd43368bd83 Mon Sep 17 00:00:00 2001 From: EKar Date: Mon, 1 May 2023 20:56:31 +0800 Subject: [PATCH] fix: Fix sample code path error --- src/content/docs/en/core-concepts/endpoints.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/en/core-concepts/endpoints.mdx b/src/content/docs/en/core-concepts/endpoints.mdx index 7e9a3448588d5..1903443a1ae2b 100644 --- a/src/content/docs/en/core-concepts/endpoints.mdx +++ b/src/content/docs/en/core-concepts/endpoints.mdx @@ -54,7 +54,7 @@ export const get: APIRoute = async function get ({params, request}) { 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: -```ts title="src/pages/[id].json.ts" +```ts title="src/pages/api/[id].json.ts" import type { APIRoute } from 'astro'; const usernames = ["Sarah", "Chris", "Dan"] @@ -77,7 +77,7 @@ export function getStaticPaths () { } ``` -This will generate three JSON endpoints at build time: `/api/1.json`, `/api/2.json`, `/api/3.json`. Dynamic routing with endpoints works the same as it does with pages, but because the endpoint is a function and not a component, [props](/en/reference/api-reference/#data-passing-with-props) aren't supported. +This will generate three JSON endpoints at build time: `/api/0.json`, `/api/1.json`, `/api/2.json`. Dynamic routing with endpoints works the same as it does with pages, but because the endpoint is a function and not a component, [props](/en/reference/api-reference/#data-passing-with-props) aren't supported. ### `request` All endpoints receive a `request` property, but in static mode, you only have access to `request.url`. This returns the full URL of the current endpoint and works the same as [Astro.request.url](/en/reference/api-reference/#astrorequest) does for pages.