Introduction
Velaria uses Astro API routes to handle server-side functionality. These endpoints are built using Astro’s file-based routing system and provide RESTful interfaces for client-server communication.All API routes are server-side rendered (SSR) and use
export const prerender = false to ensure dynamic handling of requests.Available endpoints
The Velaria API currently provides the following endpoints:| Endpoint | Method | Description |
|---|---|---|
/api/contact | POST | Submit contact form data and send email notifications |
How Astro API routes work
Astro API routes are defined in thesrc/pages/api/ directory. Each file exports HTTP method handlers (GET, POST, PUT, DELETE, etc.) that process requests and return responses.
Basic structure
Response format
All API endpoints return JSON responses with a consistent structure:Indicates whether the request was processed successfully
A message describing the result or error
Success response
Error response
Status codes
The API uses standard HTTP status codes:- 200: Success - Request processed successfully
- 500: Server Error - Validation failed or processing error occurred
Authentication and security
The current API endpoints do not require authentication. All endpoints are publicly accessible.
Security considerations
- CORS: Endpoints are accessible from the same origin by default
- Rate limiting: Not currently implemented
- Input validation: Server-side validation is performed on all inputs
- Email validation: Uses regex pattern
/^[^\s@]+@[^\s@]+\.[^\s@]+$/
Error handling
All endpoints use try-catch blocks to handle errors gracefully. When an error occurs:- The error is logged to the console
- A JSON response is returned with
success: false - An appropriate status code is set (typically 500)
- A user-friendly error message is provided in the
msgfield
External integrations
The Velaria API integrates with external services:- Email API:
https://email-api-bj45.vercel.app/api/mail/contact- Used to send contact form submissions via email
Making requests
To interact with the API, make HTTP requests from your client-side code:Next steps
Contact endpoint
Learn how to submit contact form data
