What problem does it solve?
You need to create server-side API endpoints and backend logic in an Astro app without fighting routing conventions or response handling.
Core Features & Use Cases
- Create API endpoints in
src/pages/api/: Automatically maps file paths to URLs like src/pages/api/hello.ts → GET /api/hello.
- Implement HTTP method handlers: Export
GET, POST, PUT, DELETE, PATCH, or ALL and return a standard Response.
- Support dynamic and catch-all routes: Use bracket filenames (e.g.,
[id].ts) and catch-alls (e.g., [...path].ts) for flexible APIs.
- Use Wix SDKs from server routes: Call packages like
@wix/data, @wix/members, and @wix/ecom directly inside endpoints.
- Handle request inputs and responses: Read JSON bodies, form data, query params, headers, and cookies; set proper JSON headers and status codes.
Quick Start
Create a file named src/pages/api/hello.ts that exports a GET handler returning new Response(JSON.stringify({ message: "Hello from the API" }), { status: 200, headers: { "Content-Type": "application/json" } }).