Call endpoints from the server
هذا المحتوى غير متوفر بلغتك بعد.
Endpoints can be used to serve many kinds of data. This recipe calls a server endpoint from a page’s component script to display a greeting, without requiring an additional fetch request.
Prerequisites
Section titled Prerequisites- A project with SSR (output: ‘server’) enabled
Recipe
Section titled Recipe-
Create an endpoint in a new file
src/pages/api/hello.ts
that returns some data: -
On any Astro page, import the
GET()
method from the endpoint. Call it with theAstro
global to provide the request context, and use the response on the page: