Skip to main content

Introduction

The C.A.R. 911 API is built on Laravel 8.x and provides a RESTful interface for managing police resources, equipment, cameras, vehicles, and operational data. The API follows Laravel conventions and uses JSON for request and response payloads.

Architecture

The API is structured around Laravel’s resource-based routing and follows MVC (Model-View-Controller) architecture:
  • Routes: Defined in routes/api.php for API endpoints and routes/web.php for web-based endpoints
  • Controllers: Handle business logic and request processing
  • Models: Eloquent ORM models for database interaction
  • Middleware: Authentication, authorization, and request validation

Authentication Layer

The application uses Laravel Sanctum for API token authentication, enabling both SPA authentication and simple token-based API access.
Laravel Sanctum is configured in config/sanctum.php and provides lightweight authentication for SPAs and mobile applications.

Base URL

Configure your base URL in the .env file:
APP_URL=http://localhost
For API requests, the base URL structure follows:
http://localhost/api

API Prefix

API routes are automatically prefixed with /api by Laravel’s RouteServiceProvider. All API endpoints should be accessed through this prefix.

Response Formats

Success Response

Successful API responses typically return JSON with the requested data:
{
  "id": 1,
  "name": "John Doe",
  "email": "[email protected]",
  "lp": "12345",
  "dni": "12345678",
  "created_at": "2024-01-15T10:30:00.000000Z",
  "updated_at": "2024-01-15T10:30:00.000000Z"
}

Error Response

Error responses include appropriate HTTP status codes and error messages:
{
  "message": "Unauthenticated."
}

Validation Error Response

Validation errors return a 422 status code with detailed field errors:
{
  "message": "The given data was invalid.",
  "errors": {
    "email": [
      "The email field is required."
    ],
    "password": [
      "The password must be at least 8 characters."
    ]
  }
}

HTTP Status Codes

The API uses standard HTTP status codes to indicate success or failure:
Status CodeDescription
200OK - Request succeeded
201Created - Resource created successfully
204No Content - Request succeeded with no response body
400Bad Request - Invalid request format
401Unauthorized - Authentication required
403Forbidden - Insufficient permissions
404Not Found - Resource not found
422Unprocessable Entity - Validation failed
500Internal Server Error - Server error

Content Type

All API requests should include the following headers:
Content-Type: application/json
Accept: application/json
Ensure you set the Accept: application/json header to receive JSON responses instead of HTML error pages.

Rate Limiting

API routes are protected by Laravel’s default rate limiting middleware, which limits requests to prevent abuse. The default configuration allows:
  • 60 requests per minute for authenticated users
  • Throttle limits can be customized in app/Http/Kernel.php
When rate limit is exceeded, you’ll receive a 429 Too Many Requests response:
{
  "message": "Too Many Attempts."
}

Available Resources

The C.A.R. 911 API provides access to the following resource categories:

Core Resources

  • Users & Authentication - User management and authentication
  • Roles & Permissions - Role-based access control using Spatie
  • Equipment (Equipos) - Equipment tracking and management
  • Vehicles (Vehiculos) - Vehicle fleet management
  • Dependencies (Dependencias) - Organizational structure management

Operational Resources

  • Cameras (Camaras) - Surveillance camera management
  • Bodycams - Body camera inventory and assignments
  • Tasks (Tareas) - Task management system
  • Resources (Recursos) - General resource allocation

Specialized Systems

  • CECOCO Integration - Real-time mobile and call tracking
  • Audio Transcription - Audio file transcription services
  • Password Vault - Secure credential management
  • Building Plans (Plano Edificio) - Device positioning and management
  • Patrimony (Patrimonio) - Asset management system
Detailed documentation for each resource endpoint will be provided in separate sections.

Data Formats

Dates and Timestamps

All timestamps follow ISO 8601 format:
"created_at": "2024-01-15T10:30:00.000000Z"

Pagination

For list endpoints, Laravel provides built-in pagination:
{
  "current_page": 1,
  "data": [...],
  "first_page_url": "http://localhost/api/resource?page=1",
  "from": 1,
  "last_page": 5,
  "last_page_url": "http://localhost/api/resource?page=5",
  "next_page_url": "http://localhost/api/resource?page=2",
  "path": "http://localhost/api/resource",
  "per_page": 15,
  "prev_page_url": null,
  "to": 15,
  "total": 75
}

CORS Configuration

The API uses fruitcake/laravel-cors package for Cross-Origin Resource Sharing (CORS) support, allowing frontend applications to communicate with the API from different domains.
Ensure CORS settings are properly configured in config/cors.php for production environments.

Build docs developers (and LLMs) love