FastAPI-JSONAPI¶
FastAPI-JSONAPI is an extension for FastAPI that adds support for quickly building REST APIs with huge flexibility around the JSON:API 1.0 specification. It is designed to fit the complexity of real life environments so FastAPI-JSONAPI helps you to create a logical abstraction of your data called “resource”. It can interface any kind of ORMs or data storage through the concept of data layers.
Main concepts¶
Features¶
FastAPI-JSONAPI has many features:
Relationship management - in developing
Powerful filtering
Include related objects - in developing
Sparse fieldsets - in developing
Pagination
Sorting
Permission management - in developing
OAuth support - in developing
User’s Guide¶
This part of the documentation will show you how to get started using FastAPI-JSONAPI with FastAPI.
- Installation
- A minimal API
- Filtering API example
- Quickstart
- Routing
- Filtering
- Include related objects
- Include nested and related, Many-to-Many
- Custom SQL filtering
- Logical data abstraction
- Resource Manager
- Data layer
- Sparse fieldsets
- Pagination
- Sorting
- Errors
- Permission
- OAuth
- Configuration
A minimal API¶
This example provides the following API structure:
URL |
method |
endpoint |
Usage |
---|---|---|---|
/persons |
GET |
person_list |
Get a collection of persons |
/persons |
POST |
person_list |
Create a person |
/persons/<int:person_id> |
GET |
person_detail |
Get person details |
/persons/<int:person_id> |
PATCH |
person_detail |
Update a person |
/persons/<int:person_id> |
DELETE |
person_detail |
Delete a person |
Request:
POST /persons HTTP/1.1
Content-Type: application/vnd.api+json
{
"data": {
"type": "person",
"attributes": {
"name": "John"
}
}
}
Response:
HTTP/1.1 201 Created
Content-Type: application/vnd.api+json
{
"data": {
"attributes": {
"name": "John"
},
"id": "1",
"links": {
"self": "/persons/1"
},
"type": "person"
},
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "/persons/1"
}
}
Request:
GET /persons/1 HTTP/1.1
Content-Type: application/vnd.api+json
Response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": {
"attributes": {
"name": "John"
},
"id": "1",
"links": {
"self": "/persons/1"
},
"type": "person"
},
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "/persons/1"
}
}
Request:
GET /persons HTTP/1.1
Content-Type: application/vnd.api+json
Response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": [
{
"attributes": {
"name": "John"
},
"id": "1",
"links": {
"self": "/persons/1"
},
"type": "person"
}
],
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "http://localhost:5000/persons"
},
"meta": {
"count": 1
}
}
Request:
PATCH /persons/1 HTTP/1.1
Content-Type: application/vnd.api+json
{
"data": {
"id": 1,
"type": "person",
"attributes": {
"name": "Sam"
}
}
}
Response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": {
"attributes": {
"name": "Sam"
},
"id": "1",
"links": {
"self": "/persons/1"
},
"type": "person"
},
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "/persons/1"
}
}
Request:
DELETE /persons/1 HTTP/1.1
Content-Type: application/vnd.api+json
Response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"jsonapi": {
"version": "1.0"
},
"meta": {
"message": "Object successfully deleted"
}
}
API Reference¶
If you are looking for information on a specific function, class or method, this part of the documentation is for you.