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, read Using RestView for the default CRUD contract, then use Build a Blog API for a complete multi-model example. 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
Project structure

Lay out a growing application by subject, keep imports pointing one way, and compose views and models from one place each.

Project structure
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
Current context

Bind the current user per request. Read the value in application code, column defaults, and tests.

Current context
Query Clauses

Compose reusable SQLAlchemy predicates. Supply values through context members when applying the clauses to a statement.

Query Clauses
Scopes

Impose a replaceable clause on every read and every reference to a model. Use a default scope for row surfaces such as live and deleted records.

Scopes
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 CRUD 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
Nested Resources

Serve a child resource under its parent, such as /projects/{project_id}/tasks, with paging, filters, sort and every CRUD route.

Nested Resources
Customizing RestView

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

Customizing 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

Put cross-cutting concerns (tenant scoping, soft delete, audit stamping) where they belong: structural fields on the model, verbs on view 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 default CRUD 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