SolidX

Swagger Documentation

This section provides details on how to access and use the Swagger documentation for SolidX REST APIs.

SOLID automatically generates comprehensive API documentation for all your endpoints using Swagger/OpenAPI specification. This documentation provides developers with an interactive interface to explore and test the APIs.

Accessing API Documentation

To access the Swagger documentation:

  1. Navigate to your SOLID installation
  2. Go to /api/docs endpoint
  3. You'll see the Swagger UI with all available endpoints

Authentication

Before using the APIs, you'll need to authenticate:

  1. Use the /api/auth/login endpoint
  2. Provide your credentials
  3. Receive a JWT token
  4. Use this token in the Authorization header for subsequent requests

Example Authentication Flow

# Login request
POST /api/auth/login
{
  "email": "user@example.com",
  "password": "yourpassword"
}

# Response
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "user": {
    "id": 1,
    "email": "user@example.com",
    ...
  }
}

# Using the token
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

API Structure

Resource Endpoints

Each resource in your SOLID app automatically gets the following RESTful endpoints:

MethodEndpointDescription
GET/api/{resource}List resources
GET/api/{resource}/{id}Get single resource
POST/api/{resource}Create resource
PUT/api/{resource}/{id}Update resource
DELETE/api/{resource}/{id}Delete resource

Query Parameters

The list endpoint supports various query parameters:

ParameterDescriptionExample
filtersFilter records?filters[status]=active
sortSort records?sort=created_at:desc
paginationPaginate results?page=1&limit=10
populateInclude relationships?populate=author,comments
fieldsSelect specific fields?fields=title,content

Example Requests

List Records with Filtering

GET /api/posts?filters[status]=published&sort=created_at:desc

Create Record

POST /api/posts
{
  "title": "New Post",
  "content": "Post content",
  "status": "draft"
}

Update Record

PUT /api/posts/1
{
  "status": "published"
}

Error Handling

All API errors follow a consistent format:

{
  "error": {
    "status": 400,
    "name": "ValidationError",
    "message": "Title is required",
    "details": {
      "fields": {
        "title": ["This field is required"]
      }
    }
  }
}

Common Error Codes

CodeDescription
400Bad Request - Invalid input
401Unauthorized - Authentication required
403Forbidden - Insufficient permissions
404Not Found - Resource doesn't exist
422Unprocessable Entity - Validation failed
500Internal Server Error

Best Practices

Authentication

  • Always use HTTPS
  • Keep tokens secure
  • Implement token refresh
  • Handle token expiration

Request Optimization

  • Use field selection
  • Implement pagination
  • Optimize queries
  • Cache responses

Error Handling

  • Validate input data
  • Return meaningful errors
  • Log API errors
  • Handle rate limiting

Documentation

  • Keep examples up-to-date
  • Document all parameters
  • Include response examples
  • Note any limitations