DEV Community

Danny Parker
Danny Parker

Posted on

How to Build REST API with SQL in One Minute

DBAPI is a low-code API development tool that allows you to write SQL directly on the web page to generate REST APIs. This guide will walk you through the quick start process of using DBAPI from a beginner's perspective.

Prerequisites

  • A MySQL database with a student information table structured as follows:

Student Information Table Structure

  • Requirement: Develop an HTTP API at http://127.0.0.1:8520/api/student/detail with a numeric id parameter to query student information.

Example: Accessing http://127.0.0.1:8520/api/student/detail?id=7 retrieves specific student information.

Step-by-Step Guide

1. Create a Data Source

  1. Navigate to the data source page and click the New Data Source button.

Create Data Source Button

  1. In the popup window, enter your MySQL connection details (address, account, password) and save.

Data Source Configuration

  1. After saving, the new data source will appear in your list.

Data Source Created

2. Create an API Group

  1. Go to the API page and click New Group.

Create API Group Button

  1. Enter a group name in the popup and save.

  2. The new group will appear in the left sidebar (initially empty).

API Group Created

3. Create a New API

  1. Click New API within your group to open the API creation page.

New API Button

  1. Configure basic API information:
    • Set API path
    • Create id parameter
    • Keep Content-Type as default
    • Set access permission to Public (for testing)

API Basic Information

4. Configure API Executor

  1. Click on the Executor tab
  2. Select your newly created local-mysql data source
  3. Enter the SQL query:
   select * from student where id = #{id}
Enter fullscreen mode Exit fullscreen mode

API Executor Configuration

  1. Click Save to create the API

5. Publish and Test the API

  1. After saving, the API will appear in your group but will be grayed out (unpublished).

Unpublished API

  1. Click the Online button to publish the API.

Publish API

  1. Once published, the API will be active with a Test button available.

Published API

  1. Click API Request Test to open the testing interface:
    • Enter id parameter value (e.g., 7)
    • Click Send Request
    • View returned student data

API Testing

  1. Alternatively, test via browser by accessing: http://127.0.0.1:8520/api/student/detail?id=7

Browser Testing

Conclusion

You've successfully created and deployed a REST API in under a minute with no coding required!

Additional Resources

For more advanced usage and tips, visit the DBAPI official website.

Top comments (0)