Source code for "How to Supercharge Full Stack Development with FastAPI & SDK Generation" article published on:
- Clone repository
git clone [email protected]:Sideko-Inc/fastapi-sideko.git
- Create & activate virtual python environment
# Python >= 3.8
python3 -m venv .venv
source .venv/bin/activate
- Install Server & UI Dependencies
pip install -r requirements.txt
cd sdk/bookstore-typescript && npm i && cd ../..
cd bookstore-ui && npm i && cd ../
- Configure Sideko SDK generator key
sideko login
# login via browser pop-up
- Start FastAPI server
python server.py
- Start the NextJS Dev server
cd bookstore-ui
npm run dev
See how SDK code generation seamlessly builds with FastAPI development by completing the following exercise:
- Extend the API by adding a POST /books endpoint that accepts a new pydantic model
NewBook
(contains all the same fields asBook
without theid
) - Give the endpoint an
operation_id
, this will become the function name in the generated typescript SDK- feel free to keep this as a snake case name (i.e.
add_book
), Sidkeo will handle making this camel case in typescript
- feel free to keep this as a snake case name (i.e.
- Implement the endpoint logic:
- Create a
Book
from the providedNewBook
body - Add the newly created book to the in-memory
database
list - Notice how the
lifespan
method will automatically generate an updated SDK in typescript
- Create a
- Implement a
New Book
button inbookstore-ui
that calls the new POST route
Use the CLI sideko generate
command to generate SDKs in other supported languages, for example:
# while the FastAPI server is running
sideko generate http://localhost:8000/openapi.json python -o ./sdk
Feel free to reach out with any comments or questions to [email protected]
or leave a comment on the Medium article