Examples
You can refer to the example
folder for different use cases.
The example_service
contains a minimal FastAPI application for task management with CRUD endpoints for users
and tasks
.
It uses in-memory dictionaries for data storage, so of course this is just for testing and learning purposes.
It comes with a set of test files which test compatibility with 3 different types.
- Pydantic BaseModel
- Python dataclasses
- No class, rely on dicts and lists
Packages Used¶
Installation¶
To run the example FastAPI application, simply go to the example directory at the project root, and run bash run.sh
, and you shoule be able to access the Swagger docs at http://localhost:8080/docs
Alternatively, you can set up your own virtualenv, and install the requirements.example.txt
and run uvicorn app.main:app
.
To generate the Arrest boilerplate from the OpenAPI specs, simply run the FastAPI application using uvicorn
at http://127.0.0.1:8080/docs, and run the arrest CLI as followed:
$ arrest -u http://localhost:8080/openapi.json -d example_service
models.py
, containing the Pydantic schemas corresponding to the OpenAPI components, a resources.py
containing the RESTful resource definitions and a services.py
containing the service definition that includes the resources.
To use the service, simply call example_service.users.get("")
.
Running Tests¶
Create a virtualenv that contains the dependencies in the example directory, and run pytest -vvv
.