Dittofi
Search…
CRUD Endpoints & Actions
Learn how to build CRUD apps inside Dittofi.
In our last two tutorials, we have learnt how to read & write data from & to our backend. The reading & writing operations are part of what are known as CRUD operations. CRUD stands for, Create, Read, Update & Delete.
  • Create operations allow you to give your apps the ability to accept users writing data to your backend.
  • Read operations give your apps the ability to fetch data from your backend to display.
  • Update & Delete operations meanwhile give your apps the ability to edits & delete data from your backend.
60% - 70% of all apps are built out of the CRUD operations. For example, if you wanted to build a social media feed, you’d want your app to allow users to create posts, edit posts, delete posts, whereas if you were building an event management system, you would need to give your users the ability to create events, edit event times & delete events.
In this section we are going to cover the Update & Delete events. For reference to Create & Read events, see Guides Build a sign up form & Build a to-do list app.

Step 1 Create a posts table

For the purpose of this example, create a new table called “Posts” & add the columns username & posts. Users will be able to edit & update posts. Add a few usernames & posts directly to your table for testing.

Step 2 Update endpoint, action & event

We start by building our update endpoint.

Creating an update endpoint

To build the update endpoint & associated action & event, we start by creating a new endpoint & giving it the name, “update post”, set the path to “/v1/update_post/{id}/” & the request method to Put.
You’ll notice on the path, we append our usual text with the text {id}.
Right now this is a placeholder that represents the unique “id” of the record that we want to update in our Posts table. It is what is called a “Path” variable.
In order to set the “id” in our path, we need to add a “Path” variable to our endpoint. This can be done from the variables section on the endpoint.
Notice, the Kind is set to number & the word “id” needs to match exactly with the extension of the path, otherwise your endpoint will not work.
Lastly, our endpoint is going to need a body variable. This body variable will contain the updated post information that will be sent to our endpoint.
After you’ve done this, we will head over to the actions page to build our associated Action & Update Event.

Creating an update action & event

First, let’s start by creating the action & calling it “update user posts”.
Next, we set the trigger to “Endpoint” & associate our action with our Update Event endpoint.
Next we need to find a record inside our Posts table to update. To do this, we need to use the “id” sent from our endpoint as a path variable to filter for the record that we want to update. We can do this by using the Variables section at the bottom of our action.
Next, we add an update event & take the Object that we just filtered for in our Posts table. We can take this Object & assign a new value to the post property, thereby updating the post.
We can save our action, generate the code & test the Update event out from inside our endpoint. To test, select a post that you’d like to update from the Posts table. When you run the endpoint, enter the id of that post as a path variable & enter some text for the post that you want to update.

Step 3 Delete endpoint, action & event

To build the delete endpoint & associated action & event, we can use the same Posts table. Start by creating a new endpoint & giving it the name, delete posts, set the path to /v1/delete_posts/{id}/ & set the request method to “Delete”.
Note that as with the Update event, we use the path variable “id”, so that the users can know which of the posts in our Posts table to delete. To set this up, add a path variable & make sure that the name of your path variable matches the “id” used in your endpoints path.

Creating a delete action & event

Next & as always, we need to set up the associated action & event. To do this, head on over to the actions & events tab & create a new action called “Delete post”.
Next, set the trigger to endpoint, associate the action with your Delete posts endpoint.
Next, we need to configure our action to look up the object in our Posts table that we are going to delete. To do this, add a variable of Kind “Model”, give it the Label & Name “Post To Delete”, pick the model “Posts” & configure the action.
Next, add the delete event to your actions & events graph, pick the object that we look up within our action to delete & press save & close.
We have now completed the setup of our Delete endpoint, action & event. We can generate the code & test the functionality against the test data from within the delete posts endpoint.
To test, pick the id of a record in your Posts table that you want to delete & enter this as your path variable when prompted to.

Onwards!

You now know how to manually build CRUD functionality for your app. For reference docs on each of the different actions & events see the section Reference Docs.
Next we will learn how to put the creation of Endpoints, Actions & Events on autopilot using the Dittofi Marketplace tool. You’re about to learn how to dramatically increase the speed at which you can build full stack software.
Next: Dittofi Marketplace Tool →
Last modified 6mo ago