Simple CRUD API
Overview
In this example you can see how to build a simple CRUD API using LaunchFlow. All the source code for this example can be found on GitHub. This example will show you how to use LaunchFlow to create a Cloud SQL database to hold user information, and a GCS storage bucket to hold profile pictures.
Code Walkthrough
There are three main files associated with our application:
infra.py
is where we define the resource our application will use. In this case we define a Cloud SQL database and a GCS bucket. When you run lf create
from the root directory of the project these resources will be created in the project and environment of your choice.
1import launchflow as lf
2
3# TODO(developer): Set these variables with your own values
4db = lf.gcp.CloudSQLPostgres("launchflow-demo-db")
5lf_bucket = lf.gcp.GCSBucket("launchflow-demo-bucket-1")
Running the application
To run this application make sure you update the launchflow.yaml
to point to your own project and environment.
Install the dependencies
1pip install -r requirements.txt
Login
To get started run login to LaunchFlow:
1lf login
Create Resources
NOTE: Before running make sure you update the bucket name in infra.py
to be unique.
To create the resources needed to run the application, run:
1lf create
This will prompt you to create a LaunchFlow project and environment to hold the resources. It takes GCP several minutes to provision your Cloud SQL database.
Run the application
1uvicorn app.main:app
Once running you can visit http://localhost:8000/docs to see the API documentation, and send requests.