In this tutorial, you will learn how to create an API route to an endpoint that will delete a specific book identified by its ID in the BookStore database.

The target route you are going to build and test should look something like this:

https://rest.synatic.com/indri/bookstore-api/Books

When executing this API request, you use a DELETE request loaded with the JSON Object, add the id of the book's record to the end of the URL, then submit the request. The response should delete the identified book.

For the DELETE Route, you will also be adding a Security Scheme to the API.


Watch the video below to learn how to create the API Route using the Synatic platform.

The following topics explain each step of the process as shown in the video.


Let's create an API

The BookStore API has already been created in the API tutorial - Part 2, so you only need to create the required Flow and Paths and then add them to the API.

This tutorial will guide you through creating a DELETE operation to remove a book identified by its ID only.

  1. To do this, you must first create a backing Synatic flow that will access the database to delete the data, which you then connect to the API.

  2. Then you will create an API path and connect the Flow to the API.

  3. Lastly, you can test the Route using Postman.


Create the backing Flow for the Delete Book by ID route

This flow requires the following steps to be configured; Input Parameters, JSON, and SQL Server.

Open the Solution menu:

  1. Click ⨁ adjacent to the Flows option to create a new Flow.

  2. Give it the name 'Delete Book by ID' and a meaningful description.

  3. Click Save to open the flow designer canvas.


Create an 'id' parameter in the flow

You will be accessing a SQL database that requires the Key ID in the database to link to the parameter ID.

To delete a book by its ID, you must first create an Input Parameter for the ID in the flow.

Synatic - Flow Input Parameters

Select the Input Parameter step in the flow.

Synatic - API Input Parameter create
  1. Enter 'id' for the parameter name.

  2. Select the data type as Integer and also the required attribute.

  3. Click Save.


Add a JSON step

  1. You will be submitting a JSON data file to delete a record from the SQL database, so let's insert a JSON step from the Reader drawer in the Steps palette to read a JSON formatted script.

  2. Select and drag it to the flow.

  3. The JSON step opens. Click to save it as no configuration is required.


Add the SQL Server step

  1. You will be accessing the SQL database to delete a record, so let's insert the SQL Server step from the Destination drawer in the Steps palette.

  2. Select and drag it to the flow.

  3. The SQL Server step opens.

Synatic - Flow SQL Server Command

SQL Server database connection

When the Flow is saved, the SQL Server step configuration will open.

  1. The connection to the database already exists.

  2. You just need to select a connection.

  3. Click on the SQL Server connection field and select the BookStore Connection.


Write the Query

Now you can enter the SQL Query to delete a specific book selected by its ID from the database.

  1. Select the Delete Query type.

  2. Enter the following in the SQL Command code block:
    DELETE
    FROM
    tutorials.BookStore
    WHERE
    id = {{parameters.id}};
    📝 Synatic uses the Handlebars template {{ ... }} to access parameters.

  3. Click Save Step.

Synatic - Flow Designer canvas

Test the Connection and the Query

It's always going to be a good idea, and advisable to test the query before continuing.

  1. Click the blue Run Test button on the Flow to run a simulation.
    📝 You'll see that an Input Parameter entry field is now available.

  2. Enter the ID of the book that you want to delete.

Test the Query

  1. Click Test to execute the query.

  2. You should check the response to verify that the connection is working and that the record was deleted successfully.


Connect the Flow to the API Route

To complete the API, the Delete Book by ID backing Flow must be connected.

  1. Open the API Builder again.

  2. Click ⨁ adjacent to the Paths tab to create a new Route.

  3. Select the DELETE operation and type in the Path's name /Books/{id}.

  4. Select the Definition tab and add the API Key Scheme you created earlier.

  5. Select the Source tab and then the Flow tab.

  6. Scroll to select the Flow Delete Book from the available list.

Synatic - API Paths tab

Test the API Route with Postman

You can test your API endpoint using the Postman platform.

  1. Open the API Builder again.

  2. Select the info tab and copy the Service URL.

  3. Launch Postman, select a DELETE request and paste the URL
    https://rest.synatic.com/indri/bookstore-api

  4. Add '/Books/5' to the URL. (5 is the ID of the book.)

  5. Click Send to test the deletion.

Synatic - API Test

< API Path to UPDATE a book Back to Start >

Did this answer your question?