API communication - chrisdacel/Backend_EcoRisaralda GitHub Wiki
API Communications
General Description
The system API is developed under a REST architecture using the Laravel framework. Its purpose is to enable communication between the frontend and backend through data exchange in JSON format over the HTTP protocol.
The API implements token-based authentication using the auth:sanctum middleware, ensuring that only authenticated users can access protected resources.
Base Server (Local Environment):
http://localhost:5173/api
Endpoint Documentation (API URLs)
Authenticated User Endpoint
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /users | Returns the authenticated user's information | Yes (Token) |
User Management (CRUD)
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /users | Retrieves the list of users | Yes |
| GET | /users/{id} | Retrieves a specific user | Yes |
| POST | /users | Creates a new user | Yes |
| PUT | /users/{id} | Retrieves a specific user | Yes |
| DELETE | /users/{id} | Delete a specific user | Yes |
Request and Response Structure
Request Format
Requests to the server must be sent in JSON format:
{
"name": "Juan Pérez",
"email": "[email protected]",
"password": "123456"
}
Asynchronous Messages
Currently, the API operates under a synchronous model based on HTTP requests (Request-Response).
No asynchronous messaging mechanisms such as queues (Queues), WebSockets, or distributed events are implemented.
However, Laravel allows the future implementation of:
- System events
- Queue jobs
- Notifications
- Real-time broadcasting
This would facilitate a more scalable and decoupled architecture.
Service Contracts
The contract between the frontend and backend is defined by:
- The routes exposed in api.php
- The HTTP method used
- The input and output JSON structure
- The token-based authentication mechanism
The frontend must comply with:
The required data structure for each endpoint HTTP response status codes Mandatory authentication for protected endpoints