You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(fastapi): refresh integration guide for default provider (#54)
- Document the shipped FastAPIProvider as the primary, batteries-included path
- Add Default Configuration section for FastAPIConfig fields
- Add config publishing via 'provider:publish --provider fastapi'
- Demote the custom provider example to an advanced subsection
- Fix serve command to 'uv run artisan serve'
The `FastAPIProvider`is responsible for initializing the `FastAPI` instance and registering it with the application container. You can customize your FastAPI instance by extending this provider.
42
+
The `FastAPIProvider`shipped with Fastapi Startkit is the default, batteries-included entry point. Once registered (see [Setup](#setup)), it configures everything needed to run a FastAPI application — you do **not** need to write your own provider to get started.
43
43
44
-
### Customizing the Instance
44
+
Across its two boot phases it:
45
45
46
-
To change the title, version, or add global exception handlers, you can create your own provider:
46
+
-**`register()`** — loads the FastAPI configuration (merging your published `config/fastapi.py` over the framework defaults) and creates the `FastAPI` instance, binding it into the application container via `use_fastapi()`.
47
+
-**`boot()`** — registers the `serve` console command, wires the framework's exception handlers (so `HTTPException`, request-validation errors, and otherwise uncaught exceptions are rendered through the exception manager), and publishes the default `config/fastapi.py` so you can export and edit it.
48
+
49
+
Registering `FastAPIProvider` in your providers list is all that is required — the FastAPI instance, the `serve` command, and exception handling are wired up for you.
50
+
51
+
## Configuration
52
+
53
+
### Default Configuration
54
+
55
+
FastAPI settings are defined by the `FastAPIConfig` dataclass, with values sourced from environment variables:
-`app_url` — the host and port the `serve` command binds to.
65
+
-`reload` — whether Uvicorn watches for code changes and restarts automatically.
66
+
-`reload_dirs` — an optional list of directories to watch; `None` lets Uvicorn use its default.
67
+
-`reload_excludes` — glob patterns Uvicorn ignores while watching for changes.
68
+
69
+
For most applications, setting `APP_URL` and `APP_RELOAD` in your `.env` is all you need:
70
+
71
+
```bash
72
+
# .env
73
+
APP_URL=http://127.0.0.1:8000
74
+
APP_RELOAD=true
75
+
```
76
+
77
+
### Publishing the Config
78
+
79
+
To customise the configuration beyond environment variables — for example to change `reload_dirs` or `reload_excludes` — export the default config file into your project with the `provider:publish` command:
80
+
81
+
```bash
82
+
uv run artisan provider:publish --provider fastapi
83
+
```
84
+
85
+
This copies the framework's default configuration into your project at `config/fastapi.py`, where you can edit it directly:
The provider merges this file over the framework defaults at boot, so you only need to keep the fields you want to override.
109
+
110
+
## Advanced: Customizing the Provider
111
+
112
+
The default provider is enough for most applications. If you need full control over the `FastAPI` instance — for example to change the title and version, or to add custom middleware — you can write your own provider and register it in place of `FastAPIProvider`:
47
113
48
114
```python
49
115
# app/providers/fastapi_provider.py
@@ -69,6 +135,8 @@ class MyFastAPIProvider(Provider):
69
135
])
70
136
```
71
137
138
+
When you supply your own provider you take over instance creation, so remember to register any commands (such as `ServeCommand`) and exception handlers you still want.
139
+
72
140
## Routing
73
141
74
142
Fastapi Startkit supports the standard FastAPI routing approach as well as a `Router` wrapper that adds a more expressive, MVC-style API on top.
@@ -288,13 +356,13 @@ class MyFastAPIProvider(Provider):
288
356
289
357
## Serving the Application
290
358
291
-
When you register the `ServeCommand` in your provider, you gain access to the `serve` CLI command:
359
+
The default `FastAPIProvider` registers the `serve` CLI command for you (when you use a custom provider, register `ServeCommand` yourself). Start the server with:
292
360
293
361
```bash
294
-
uv run python artisan serve
362
+
uv run artisan serve
295
363
```
296
364
297
-
This command uses Uvicorn to start your application with reasonable defaults and reload capabilities.
365
+
This command uses Uvicorn to start your application, honouring the `app_url`, `reload`, `reload_dirs`, and `reload_excludes` values from your [FastAPI configuration](#configuration).
0 commit comments