Documentation Index
Fetch the complete documentation index at: https://docs.veloiq.dev/llms.txt
Use this file to discover all available pages before exploring further.
create_crud_router generates five standard REST endpoints for any SQLModel table class and returns them as a FastAPI APIRouter. The generated router is the entire API layer for the common case — a database table with list, get, create, update, and delete operations. Each generated module’s api.py uses this function, and the module auto-loader registers the router with the FastAPI application automatically.
Generated endpoints
The URL prefix defaults to/<tablename> based on the model’s __tablename__ attribute.
| Method | Path | Description |
|---|---|---|
GET | /{model} | Paginated list. Accepts _start, _end, _sort, _order, and column filter parameters. |
GET | /{model}/{id} | Fetch a single record by primary key. |
POST | /{model} | Create a new record. Returns the created record with status 201. |
PUT | /{model}/{id} | Full update — replaces all writable fields. |
PATCH | /{model}/{id} | Partial update — sets only the fields present in the payload. |
DELETE | /{model}/{id} | Delete a record. Returns status 204. |
List endpoint
Query parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
_start | int | 0 | Zero-based offset of the first record to return. |
_end | int | 25 | Zero-based offset of the last record (exclusive). Returns _end - _start records. |
Column filters
Any query parameter whose name matches a column name on the model is applied as an exact equality filter:__ilike to a column name for a case-insensitive contains match:
_ are reserved for pagination and are not interpreted as column filters.
Response headers
List responses include two headers required by the Refine data provider pagination convention:| Header | Format | Example |
|---|---|---|
x-total-count | Integer string | "42" |
content-range | items <start>-<end>/<total> | "items 0-25/42" |
expose_headers in the middleware configuration) so the frontend can read them cross-origin.
Example list response
Every record in list and get responses includes a
_label field — a human-readable string computed by the model’s build_model_str_label method. The frontend uses this for relation selectors and breadcrumbs.Authentication
Whenauth_enabled is True (the default), all generated endpoints require a valid JWT Bearer token in the Authorization header. Unauthenticated requests receive a 401 response. Requests with a valid token but insufficient role permissions receive 403.
VELOIQ_AUTH_DISABLED=1.
Access control integration
The CRUD router integrates with all three access control layers automatically:- Layer 1 (global roles): The RBAC middleware checks whether the user’s roles permit the HTTP method before the endpoint handler runs. Unauthorized methods return
403. - Layer 2 (model-level):
@model_accessexceptions are enforced per-model. A Viewer that has read-only global permissions and is further restricted on a specific model via@model_accesswill receive403on forbidden actions. - Layer 3 (field-level):
veloiq_field(read_roles=…, write_roles=…)restrictions are applied at runtime. Read-restricted fields are silently omitted from responses; write-restricted fields are silently dropped from create/update payloads. - ReBAC (row-level): If the model carries a
@rebacdecorator, the list query and single-record fetch both apply the row-level filter. Inaccessible rows return404.
Usage
api.py. Import router from api.py in your custom_api.py:
api.py and custom_api.py automatically. See Custom Endpoints for the full guide.
Python API
create_crud_router signature, base models, and access control decorators.Configuration
Configure auth, CORS, and database connection.