Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/advanced/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ class UserEndpoint(RestEndpoint):

- You can also override the `validate(self, data: dict)` method directly for full-body validation.
- Combine with filtering and pagination for robust endpoint logic.

## 5. Automatic Datetime Parsing

LightAPI automatically parses string values for columns of type `DateTime` and `Date`. It uses the `python-dateutil` library to flexibly parse a wide range of formats, including:

- `YYYY-MM-DDTHH:MM:SS`
- `YYYY-MM-DDTHH:MM:SS.ffffff`
- `YYYY-MM-DDTHH:MM:SS+HH:MM` (with timezone)
- `YYYY-MM-DD`

If a string cannot be parsed as a valid datetime, a `400 Bad Request` error is returned with a descriptive message.
4 changes: 1 addition & 3 deletions docs/getting-started/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ from lightapi import LightApi
from app.models import User

app = LightApi()
app.register({
'/users': User
})
app.register(User)

if __name__ == '__main__':
app.run(host='127.0.0.1', port=8000)
Expand Down
15 changes: 9 additions & 6 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ from lightapi import LightApi
from models import User, Post

app = LightApi(database_url="sqlite:///blog.db")
app.register({
'/users': User,
'/posts': Post
})
app.register(User)
app.register(Post)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
Expand All @@ -132,9 +130,14 @@ if __name__ == '__main__':

Once your API is running, you can test it in several ways:

### 1. Interactive Swagger Documentation
### 1. Interactive API Documentation

Visit **http://localhost:8000/docs** in your browser for an interactive API documentation interface where you can:
LightAPI provides two interactive documentation interfaces out of the box:

- **Swagger UI**: Visit **http://localhost:8000/docs** in your browser.
- **ReDoc**: Visit **http://localhost:8000/redoc** for an alternative documentation layout.

Both interfaces allow you to:
- Browse all available endpoints
- Test API calls directly from the browser
- View request/response schemas
Expand Down
38 changes: 38 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ This guide covers common issues you might encounter when using LightAPI and thei

## Runtime Errors

### Understanding Error Responses

LightAPI now provides detailed error responses in debug mode to help with troubleshooting.

#### Validation Errors (4xx)

When a request fails due to invalid data (e.g., missing required fields, incorrect data types), you will receive a `4xx` status code with a JSON body describing the error.

**Example: Unique Constraint Violation (`409 Conflict`)**
```json
{
"error": "Unique constraint violated for users.email."
}
```

**Example: Invalid Datetime Format (`400 Bad Request`)**
```json
{
"error": "Invalid datetime format for field 'published_date'"
}
```

#### Server Errors (500)

When an unexpected server error occurs, LightAPI will return a `500 Internal Server Error` with a detailed JSON body in debug mode.

**Example: 500 Error Response (in debug mode)**
```json
{
"error": "Internal Server Error",
"message": "...",
"traceback": "..."
}
```

In production mode (`debug=False`), the `message` and `traceback` fields are omitted to avoid leaking sensitive information.


### Content-Length Errors

**Error**: `RuntimeError: Response content longer than Content-Length`
Expand Down
Loading
Loading