Skip to content

Commit 1d89ca7

Browse files
committed
example "webapp": Install "rest-rpc" from PyPI
1 parent f17bac0 commit 1d89ca7

File tree

3 files changed

+2
-16
lines changed

3 files changed

+2
-16
lines changed

examples/webapp/README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22

33
This is a small example for a web app that is written with the help of REST-RPC and [PyScript](https://pyscript.net/).
44

5-
Here, the complete front-end is located inside the `static` directory. The front-end logic is inside `static/main.py`.
5+
Here, the complete front-end is located inside the `static` directory. The front-end logic is inside `static/main.py`. Since the `static/pysript.toml` contains `rest-rpc` as a dependency, it is automatically installed from PyPI. `static/my_api.py` on the other hand is symlinked from `./my_api.py`.
66

77
Inside `./main.py`, you'll find that the FastAPI app that is auto-generated from REST-RPC via `api_impl.make_fastapi()` is re-routed to `/api` and that `/` points to the `static` directory. This means that you'll find the `read_item` method under `/api/items/{item_id}` instead of simply `/items/{item_id}`. This has to be considered by the front-end: Here, we are using `ApiClient(..., base_url="/api/")`.
88

9-
> [!CAUTION]
10-
> This example takes multiple shortcuts that are not suited for production use.
11-
>
12-
> For example, the `rest_rpc` module is served statically here. This is not a good idea in general for multiple reasons. One of them is that the `static/rest_rpc/__pycache__` directory will be served statically and the containing files contain sensitive information.
13-
14-
Since `rest_rpc` was symlinked here for simplicity, the dependency management is not handled by PyScript. This means that we need to explicitly depend on `pydantic` inside the `static/pyscript.toml`.
15-
169
By the way, if you want to use Pyodide without Pyscript, you can do that too. In this example, you can see for yourself that you can also use `engine="pyodide"` and it will still work (since PyScript uses Pyodide internally here). So you can simply install REST-RPC inside your Pyodide environment.
1710

1811
## Usage
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
packages = ["pydantic"]
1+
packages = ["rest-rpc"]
22

33
[files]
4-
"./rest_rpc/__init__.py" = "./rest_rpc/__init__.py"
5-
"./rest_rpc/api_client.py" = "./rest_rpc/api_client.py"
6-
"./rest_rpc/api_definition.py" = "./rest_rpc/api_definition.py"
7-
"./rest_rpc/api_implementation.py" = "./rest_rpc/api_implementation.py"
8-
"./rest_rpc/request_params.py" = "./rest_rpc/request_params.py"
9-
"./rest_rpc/route.py" = "./rest_rpc/route.py"
104
"./my_api.py" = ""

examples/webapp/static/rest_rpc

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)