CRUD APIs for a TODO App
In this guide, we are going to build CRUD (create, read, update and delete) APIs for a TODO list that are going interact with the fastn internal database to manage tasks.
Last updated
In this guide, we are going to build CRUD (create, read, update and delete) APIs for a TODO list that are going interact with the fastn internal database to manage tasks.
Last updated
To start off, go to the "Flows" page from the navigation menu on the left. Add a new Flow.
Name your flow "createTask" and create it as an API.
In the "Flow Configuration" step, add a new model.
Set the new model "newTask" as the input.
Defining a model will setup the input schema for the createTask API. This API will take in a task title and create a new task with that title.
Drag and drop a database element and name it "CreateTask".
Set it up with the following query.
This query will create a table for tasks with each task having the fields id and title as attributes.
It will then insert a new task with the title passed in the input and a random uuid as the id.
Add a "Success" response and have it return a message like "New Task Created".
We can test the create task flow using the "Debugger".
This will create a new task in the database. To see the tasks, navigate to the "Databases" page and select fastn DB.
Select the "tasks" table.
Here you can see all the current tasks present in the table and filter data as needed.
Create a new API flow and name it "getTask".
Go to the Flow Configuration step and add a new model. Name it "taskById". Set it as the input model.
Add a database step with the following query.
We can test this flow in the "Debugger".
Create a new API flow and name it "getTasks".
We don't need a specific model here. So we can add the database step with the following query.
We can test this flow in the "Debugger".
Create a new API flow and name it "updateTask".
Go to the "Flow Configuration" step and add a new model. Name it "updateTask". Set it as the input model.
Add a database step with the following query.
UPDATE tasks
Add a "Success" response with an appropriate message.
We can test this flow in the "Debugger".
Create a new API flow and name it "deleteTask".
Go to the "Flow Configuration" step and set the "taskById" model we created before as the input model.
Add a database step with the following query.
Add a "Success" response with an appropriate message.
We can test this flow in the "Debugger".
After completing the setup in Parts I to IV, we should have the following flows.
To integrate a flow as an API. Go to a flow and click on "Deploy".
Once a flow is deployed, click on "Embed this Flow".
Use "Generate API Key" to create new API key with access to desired flows. Note: If you have already generated an API key with permissions for multiple flows it can be reused in the "x-fastn-api-key" header.
Once the API key is generated the auto-generated code will be updated. Select the desired programming language or copy the cURL request and integrate in your app or use it with an API tool like Postman.
Congratulations! Now you know how to integrate APIs in an application and interact with the fastn database