Skip to content

Commit 250fda0

Browse files
committed
Add docs
1 parent 4467c67 commit 250fda0

File tree

12 files changed

+1154
-31
lines changed

12 files changed

+1154
-31
lines changed

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ REST-RPC is for you, if you:
1515

1616
## Usage
1717

18+
> [!TIP]
19+
> Go right to the [documentation](docs/docs.md)
20+
1821
### Installation
1922

2023
To install `rest-rpc` for back-end use, run:
@@ -336,39 +339,40 @@ Another important note: In the API implementation, you don't need to add any ann
336339

337340
```python
338341
@api_def.get("/foo")
339-
def foo(bar: int = 42) -> dict[str, Any]: ...
342+
def foo(bar: int = 42, baz: Annotated[str | None, Query()] = None) -> dict[str, Any]: ...
340343

341344
# [...]
342345

343346
@api_impl.handler
344-
def foo(bar):
345-
return {"foo": bar}
347+
def foo(bar, baz):
348+
return {"bar": bar, "baz": baz}
346349
```
347350

348-
However, if you _decide_ to add annotations or default values, they _do_ have to match exactly, so these are all okay:
351+
However, if you _decide_ to add annotations or default values, they _do_ have to match exactly (except for `Annotated[]`, where you must use the first argument instead), so these are all okay:
349352

350353
```python
351354
@api_impl.handler
352-
def foo(bar: int):
353-
return {"foo": bar}
355+
def foo(bar: int, baz: str | None):
356+
return {"bar": bar, "baz": baz}
354357

355358
@api_impl.handler
356-
def foo(bar: int = 42):
357-
return {"foo": bar}
359+
def foo(bar: int = 42, baz: str | None = None):
360+
return {"bar": bar, "baz": baz}
358361
```
359362

360363
But these are not:
361364

362365
```python
363366
@api_impl.handler
364-
def foo(bar: float):
365-
return {"foo": bar}
367+
def foo(bar: float, baz: int):
368+
return {"bar": bar, "baz": baz}
366369

367370
@api_impl.handler
368-
def foo(bar = 0):
369-
return {"foo": bar}
371+
def foo(bar = 0, baz = "Baz"):
372+
return {"bar": bar, "baz": baz}
370373
```
371374

375+
372376
> [!TIP]
373377
> Personal recommendation: Keep it simple in the prototyping phase since things are likely to be changed around and you'll be annoyed by changing the signatures in two places instead of one. Once the API definition becomes stable, you can still add the annotations to the API implementation to improve expressivity.
374378
@@ -386,5 +390,4 @@ So it's probably a good idea to use `requests` or `urllib3` if you want synchron
386390

387391
- Support for authentication. At the moment, you can only do this via middlewares in the backend implementation.
388392
- Support parameters in `ApiImplementation.make_fastapi()` that are forwarded to the `FastAPI()` constructor.
389-
- Make argument annotation matching more lax (e.g. when we annotate `Annotated[int, Path()]` in the definition, it should be okay to just annotate `int` in the handler).
390393
- Missing something? Create an issue.

docs/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# REST-RPC – docs
2+
3+
To update the `docs.md` file, run:
4+
5+
```shell
6+
$ uv run pydoc-markdown
7+
```

0 commit comments

Comments
 (0)