Overview
The Solicitud Transporte API is a FastAPI-based backend system for managing transportation requests and missions for ONI Justicia. This guide will help you set up and run the API locally, and make your first API call.Prerequisites
Before you begin, ensure you have the following installed:- Python 3.8 or higher
- pip (Python package manager)
- SQL Server (for the main database)
- MongoDB (optional, for logging)
- Git (for cloning the repository)
Installation
Install dependencies
Install the required Python packages using pip:The main dependencies include:
- fastapi - Modern web framework for building APIs
- pymssql - SQL Server database driver
- pydantic - Data validation using Python type annotations
- python-dotenv - Environment variable management
- requests - HTTP library for making API calls
- jinja2 - Templating engine
Configure environment variables
Create a
.env file in the root directory with the following configuration:.env
Start the server
Run the FastAPI application using uvicorn:You should see output similar to:
The
--reload flag enables auto-reload on code changes, which is useful for development.Verify the installation
Open your browser and navigate to:
- API Root: http://localhost:8000 - Welcome page
- Health Check: http://localhost:8000/root - API health status
- Swagger UI: http://localhost:8000/docs - Interactive API documentation
- ReDoc: http://localhost:8000/redoc - Alternative API documentation
Making Your First API Call
Now that your API is running, let’s make your first request to list transport request statuses.Using cURL
Using Python
Using JavaScript
Expected Response
Creating a Transport Request
Let’s create a complete transport request with multiple destinations:When a request is created, it automatically enters the
PENDIENTE_APROBACION (Pending Approval) state. The system generates a unique code in the format SOL-{YEAR}-{MONTH}-{CORRELATIVE}.Understanding the Response Format
All API responses follow a consistent structure:Success Response
- exito:
true- Indicates the operation was successful - mensaje: Description of the operation result
- datos: The actual response data (object or array)
Error Response
Common HTTP Status Codes
| Status Code | Meaning | Example |
|---|---|---|
| 200 | Success | Data retrieved successfully |
| 201 | Created | New resource created |
| 400 | Bad Request | Invalid input data |
| 404 | Not Found | Resource doesn’t exist |
| 409 | Conflict | Operation conflicts with current state |
| 422 | Validation Error | Input validation failed |
| 500 | Internal Error | Server-side error |
Next Steps
Now that you have the API running, explore these resources:Authentication
Learn how to secure your API requests with JWT authentication
API Reference
Explore all available endpoints and their parameters
Request Lifecycle
Understand the complete workflow from request to completion
Error Handling
Learn about error handling and validation
Troubleshooting
Database connection errors
Database connection errors
If you’re experiencing database connection issues:
- Verify your SQL Server is running
- Check that the credentials in
.envare correct - Ensure the database exists
- Test connection using SQL Server Management Studio
- Check firewall rules allow connections on port 1433
Module not found errors
Module not found errors
If you see Make sure you’re using Python 3.8 or higher:
ModuleNotFoundError:Port already in use
Port already in use
If port 8000 is already in use, specify a different port:
JWT secret not configured
JWT secret not configured
If you see warnings about missing JWT_SECRET:Add the output to your
.env file as JWT_SECRET.For additional help, check the logs in the console output or review the Error Handling guide.