Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Antony-Figueroa/my-evershop-app/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
EverShop’s REST API allows you to create custom endpoints for your e-commerce application. The API follows a modular architecture where endpoints are defined within extensions using a declarative routing system.API Architecture
REST endpoints in EverShop are organized within extensions and follow a specific directory structure:Key Components
Route Configuration
Declarative JSON file defining HTTP methods, path, and access control
Middleware Chain
Optional middleware functions that run before the main endpoint handler
Endpoint Handler
Main function that processes the request and returns a response
TypeScript Support
Full TypeScript support with EverShop request/response types
Route Configuration
Every endpoint requires aroute.json file that defines its routing configuration:
route.json
Configuration Fields
Array of allowed HTTP methods. Supported values:
GET, POST, PUT, PATCH, DELETEThe URL path where the endpoint will be accessible. Can include path parameters.
Access control level for the endpoint.
public- Accessible without authenticationprivate- Requires authentication
Request/Response Types
EverShop provides TypeScript types for handling HTTP requests and responses:EvershopRequest
Extends Express.js Request with additional properties:Parsed request body (requires bodyParser middleware)
URL path parameters
URL query string parameters
HTTP request headers
EvershopResponse
Extends Express.js Response with standard methods:Sets the HTTP status code
Sends a JSON response
Sends a generic response
Middleware Pattern
Middleware functions run before the main endpoint handler. They are named using the pattern[middlewareName]endpoint.ts:
bodyParser.ts
[bodyParser]createFoo.ts
Middleware Execution Order
Middleware files are executed in alphabetical order based on the middleware name in square brackets:[auth]endpoint.ts- Authentication[bodyParser]endpoint.ts- Body parsing[validation]endpoint.ts- Validationendpoint.ts- Main handler
Response Conventions
Success Response
For successful operations, return a structured JSON response:Error Response
For errors, include descriptive error messages:HTTP Status Codes
Follow standard HTTP status code conventions:| Status Code | Use Case |
|---|---|
| 200 | Successful GET, PUT, or PATCH |
| 201 | Successful POST (resource created) |
| 204 | Successful DELETE (no content) |
| 400 | Bad Request (validation error) |
| 401 | Unauthorized (authentication required) |
| 403 | Forbidden (insufficient permissions) |
| 404 | Not Found |
| 500 | Internal Server Error |
Best Practices
Use TypeScript
Use TypeScript
Always use TypeScript for type safety and better IDE support:
Validate Input
Validate Input
Always validate request data before processing:
Use Appropriate Status Codes
Use Appropriate Status Codes
Return the correct HTTP status code for each scenario:
- 201 for resource creation
- 400 for validation errors
- 404 for not found
Structure Responses Consistently
Structure Responses Consistently
Use a consistent response format across all endpoints:
Separate Middleware Logic
Separate Middleware Logic
Keep concerns separated by using dedicated middleware files:
- Authentication in
[auth]endpoint.ts - Validation in
[validation]endpoint.ts - Body parsing in
[bodyParser]endpoint.ts
Example: Complete Endpoint
Here’s a complete example of creating a REST endpoint:Next Steps
View Endpoints
Browse available REST endpoints in this application
GraphQL API
Learn about the GraphQL API as an alternative
Creating Extensions
Learn how to create custom extensions
API Endpoints Guide
Step-by-step guide to creating API endpoints