One option when creating an API is to have the API Express automatically generate the APIs for a relational database. With this option, you can quickly generate services that:
Automatically generating APIs works with a relational database. To connect to another data sources or write a custom SQL query, use the visual service creator.
A database connection is required before you can generate REST APIs. Learn how to create a database connection.
To start generating APIs follow the steps below.
Your database table must have one primary key. A tables with more than one primary keys are not currently supported.
- Click the new service link.
- Select the first option: Generate REST API (this should be selected by default).
- Enter the API endpoint name. This string will be part of the API URL.
- Enter an optional (recommended) description.
- Next select a database connection. By default, all Appery.io Databases are available with predefined prefix [appery.io].
- Next, select a table.
Once your table is selected, API Express will display the services and it will generate in the Actions section. You can generate the following API services:
Below the Actions section you will see a table, which shows the columns information from the database table.
This is how database operations match to HTTP methods:
|Read (retrieve), Find||SELECT||GET|
|Update (modify)||UPDATE||PUT, PATCH|
Now, you can test all the created services. All information about testing, you can find here: Testing APIs created in API Express.
The following table will give you a general overview of using POST, GET, PUT and DELETE methods and show when to use which method:
|/accounts||Creates a new account.||Lists all accounts.||Doesn't work. PUT works with a particular object (account), not all the objects.||Doesn't work. DELETE works with a particular object (account), not all the objects.|
|/account/123||Doesn't work. POST works when creating a new object (account), not working with an existing object.||Returns account 123.||Updates account 123.||Deletes account 123.|
To learn about parameters available for each action, please go to Testing page.
- Here is a video example generating APIs for a relational database: Exposing SQL Database via REST APIs Using API Express
- How to Expose a SQL Database via a REST API in 5 Minutes
Updated over 1 year ago