Skip to content

Example FastAPI project that automatically generates a Typescript SDK with Sideko

Notifications You must be signed in to change notification settings

Sideko-Inc/fastapi-sideko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI x Sideko - Generate SDKs as you go

Source code for "How to Supercharge Full Stack Development with FastAPI & SDK Generation" article published on:

Setup

  1. Clone repository
git clone [email protected]:Sideko-Inc/fastapi-sideko.git
  1. Create & activate virtual python environment
# Python >= 3.8
python3 -m venv .venv
source .venv/bin/activate
  1. Install Server & UI Dependencies
pip install -r requirements.txt
cd sdk/bookstore-typescript && npm i && cd ../..
cd bookstore-ui && npm i && cd ../
  1. Configure Sideko SDK generator key
sideko login
# login via browser pop-up
  1. Start FastAPI server
python server.py
  1. Start the NextJS Dev server
cd bookstore-ui
npm run dev

Exercise

See how SDK code generation seamlessly builds with FastAPI development by completing the following exercise:

  1. Extend the API by adding a POST /books endpoint that accepts a new pydantic model NewBook (contains all the same fields as Book without the id)
  2. 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
  3. Implement the endpoint logic:
    • Create a Book from the provided NewBook 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
  4. Implement a New Book button in bookstore-ui that calls the new POST route

Generate other languages

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

Contact

Feel free to reach out with any comments or questions to [email protected] or leave a comment on the Medium article

About

Example FastAPI project that automatically generates a Typescript SDK with Sideko

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published