Skip to main content
All CollectionsTutorialsAPI Builder/Gateway
2. API Tutorial - Route to Get All Books
2. API Tutorial - Route to Get All Books

Create an API Route to list all books in our BookStore database

Praise Magidi avatar
Written by Praise Magidi
Updated over a week ago

In this tutorial, you will learn how to create a new API and including an API Route to an endpoint that will extract a list of all books from the BookStore database.

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

When executing the API request, the response should return the book information of all books in the BookStore database.

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

In Synatic, go to the API Builder menu and click ⨁ to add a new API. This new API will contain operations to manage books in the BookStore database.

Synatic- API Create
  1. Give it the name Bookstore and a meaningful description.

  2. Select RESTful as the API type.

  3. Click Save.

The Info tab of the API is opened and displays the following information:

Synatic - API Info tab
  • Service - The service API endpoint is automatically created and represents your base URL.

  • Swagger - Synatic also creates a metadata document that describes your API in the Swagger format.

  • The Title and Description values default from the first time creation. You may make any edits to the Title and Description.

The first operation this tutorial will demonstrate is a GET operation and used to extract a list of all the books in the database.

  1. To do this, you must first create a backing Synatic flow to access the database and extract the data.

  2. The flow must then be connected to the API.

  3. The first path you will create is the GET route, which uses the flow to call the database and execute an operation that extracts a list of all the books.

  4. But first, you must create a new solution in Synatic.

Create the new Solution

In Synatic, go to the Solutions menu and click ⨁ to add a new Solution. This Solution will contain the API flows and all the backend logic.

  1. For this tutorial, give it the name Bookstore Backend and a meaningful description.

  2. Click Save.

  3. Next, create the Flows to manage the data.

Create the backing Flow for the Get all Books route

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

Open the Solution menu:

  1. To create a new Flow, click ⨁ adjacent to the Flows option.

  2. Give it the name Get All Books and a meaningful description.

  3. Click Save to open the flow designer canvas.

You will be accessing and reading from a SQL database.

  1. So, let's insert the SQL Server step from the Source drawer in the Steps palette.

  2. Select and drag it to the flow.

  3. The SQL Server step configuration opens.

Synatic - API SQL Server step create

Create the SQL Server database connection

Before continuing, you must first create a connection to the SQL Server database.

πŸ“ Keep in mind that you could also connect to many other data sources, for example, MongoDB, PostgreSQL, Oracle, Dropbox, or plain flat files.

  1. Click ⨁ adjacent to the SQL Server Connection to create a new Connection.

  2. Give the connection a name. For this tutorial, use 'BookStore database'

  3. Enter your SQL Server details and credentials.

  4. Click Save.

Write the Query

Now enter the SQL Query script to read all books from the database.

Enter the following in the SQL Command code block:

  1. SELECT * FROM tutorials.BookStore;

  2. 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 then click Test to execute the query.

  2. You should check the response to verify that the connection is working and that the returned data is correct.

Connect the Flow to the API Route

To complete the API, you can now connect the Get all Books backing Flow.

  1. Open the API Builder again.

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

  3. Select the GET operation and type in the Path's name /Books.
    πŸ“ The Definition tab requires no configuration at this stage.

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

  5. Scroll to select the Flow Get All Books from the available list.

Synatic - API Paths tab

Test the API Route with Postman

To test the API route, you first connect to the 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 GET request, and paste the URL.

  4. Add '/Books' to the end of the URL.

  5. Click Send to test.

  6. Now, check the response to verify that the correct list of books is returned.

Synatic - API Test

Did this answer your question?