backend

Generate Astro API routes in src/pages/api that return JSON responses.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/madmaxfarm105-hue/Comando --skill backend-madmaxfarm105-hue
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backend
Source: https://github.com/madmaxfarm105-hue/Comando/tree/main/.emdash/skills/backend
Command: npx skills add https://github.com/madmaxfarm105-hue/Comando --skill backend-madmaxfarm105-hue

SYSTEM DOCUMENTATION & REQUIREMENTS

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" } }).

Frequently Asked Questions about backend

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create server-side API routes in Astro that return JSON responses?

Astro server-side API routes are created by adding endpoint files under src/pages/api, which automatically map file paths to URLs. Each exported APIRoute handler must return a standard Response object containing JSON data with appropriate Content-Type headers for frontend consumption.

Can I use Wix SDKs like @wix/data inside Astro backend endpoints?

Yes, Wix SDKs like @wix/data, @wix/members, and @wix/ecom can be called directly inside Astro server endpoints. You import the required SDK packages within your API route files in src/pages/api and execute server-side logic before returning your JSON response.

How do I handle dynamic routing and catch-all forwarding in Astro API endpoints?

Astro API endpoints support dynamic routing and catch-all forwarding by using bracket filenames like [id].ts for dynamic route params and [...path].ts for catch-all forwarding. These files extract parameters from the URL to process varied HTTP requests within a single endpoint handler.

Why should Astro API endpoints be placed under src/pages/api to avoid SPA conflicts?

Placing Astro API endpoints under src/pages/api prevents SPA conflicts by cleanly separating server-side backend endpoints from frontend page routes. This file-based routing convention ensures HTTP requests to /api/* resolve to server handlers rather than triggering client-side application routing.

How do I parse JSON bodies, form data, and query params in Astro HTTP handlers?

Astro HTTP handlers parse JSON bodies, form data, query params, and headers by accessing the incoming Request object passed to the APIRoute handler. You extract request inputs programmatically from the request body and URL before processing CRUD methods and returning a JSON response.

Does Astro support cookie management and redirects in server-side API routes?

Astro server-side API routes support cookie management and redirects by utilizing the standard Request and Response objects within exported HTTP method handlers. You can read incoming cookies from request headers and issue redirect responses with appropriate HTTP status codes.