How-To Guides#

These guides are task-focused: each one shows how to accomplish a specific goal with FastAPI-Restly. If you are new to the framework, start with Getting Started, then the Tutorial, and come back here when you have a concrete task.

Adopting and Modeling#

These guides cover bringing Restly into a codebase and defining the models and schemas it works from.

Use Restly in an Existing Project

Adopt Restly beside existing FastAPI routes, then wire it into your sessions and models.

Use Restly in an Existing Project
Custom Schemas and Field Types

Define schemas with field aliases, write-only fields, and read-only computed fields.

Custom Schemas and Field Types
Work with Foreign Keys and Relationships

Check foreign-key columns with MustExist and resolve relationships with IDRef or IDSchema, with a 404 on missing rows.

Work with Foreign Keys and Relationships

Shaping Requests and Responses#

These guides control what list endpoints accept and what your API returns, including errors.

Response Envelopes and List Metadata

Wrap successful responses in {data} envelopes and add list metadata such as total counts, while keeping Restly’s handlers and serialization.

Response Envelopes and List Metadata
Relationship Loading and Async

Load nested relationships for responses on reads and writes, extend the loaded set, and resolve MissingGreenlet on async sessions.

Relationship Loading and Async
Filter, Sort, and Paginate Lists

Filter, sort, and paginate list endpoints using URL query parameters.

Filter, Sort, and Paginate Lists
Shape Error Responses

Learn the typed fr.exc exceptions to raise from overrides, the 422-vs-400 split, and app-wide error envelopes (problem+json).

Shape Error Responses

Customizing Views#

These guides change what the generated views do, from overriding a single method to sharing behaviour across many views.

Patterns

Find the idiomatic answers for nested resources and sub-resources, a different list schema, restoring soft-deleted rows, webhook receivers, login flows, custom actions, and tenant scoping.

Patterns
Customize RestView

Override the business methods (create, update, …), the handlers, or the endpoint methods, and add custom routes alongside generated CRUD.

Customize RestView
Share Behaviour with Base Views

Use Python inheritance to share CRUD overrides, dependencies, URL prefixes, and access control across multiple views.

Share Behaviour with Base Views
Compose Views with Mixins

Layer cross-cutting concerns (tenant scoping, soft delete, audit stamping) through cooperative mixins.

Compose Views with Mixins
Use Type Annotations

Use IDSchema, optional view generics, and typed CRUD methods without fighting the framework.

Use Type Annotations

Operating and Testing#

These guides connect the API to the outside world: frontends, OpenAPI consumers, tests, and production deployment.

React Admin Integration

Use AsyncReactAdminView to get a backend that ra-data-simple-rest connects to out of the box.

React Admin Integration
Customize the OpenAPI Schema

Set per-view tags and responses, add metadata to custom routes, replace a generated route’s documented contract, and use x-resource-ref.

Customize the OpenAPI Schema
Test APIs with RestlyTestClient and Fixtures

Start from a copy-paste conftest, work with savepoint-isolated fixtures, and consult the full fixture reference.

Test APIs with RestlyTestClient and Fixtures
Deploying

Configure a production engine, set up Alembic migrations, and follow an ASGI checklist.

Deploying