This example will guide you through creating a simple REST API endpoint that retrieves and returns data from two database tables. For our example we will use an Employee and an Office table.
In this example we will build the logic manually, however, you can also get started quicker by using the Autogenerating APIs from tables option for one of the tables first.
You can use the SQL code below to create and populate the tables used in the example or use your own tables and adjust the steps accordingly.
Open the workspace
Open the example workspace by pointing your browser to the URL:
http://[HOST]:[PORT]/ide/papihello
Where host is the server you installed Profound.js on and port is the port number Profound.js is running on. If the installation is on your PC or Mac computer, use localhost.
OR open the workspace from the ide with the Open button and then select the example workspace:
Create API file
Create a new API json file by clicking the New button and selecting API file. The file will be opened and the Canvas, Parameters, API Routes, and Properties panel will be initialized.
Set Properties
On the left hand lower panel select the General Info tab and fill on the following values
- Name: employee
- Summary: get employee information
HTTP Method: get
HTTP Path: /employee/:employeeNumber
Notice the colon before the employeeNumber. This indicates that employeeNumber is a required path parameter.
Specifying a parameter this way will automatically add it to the Input Parameters list.
- Category, Sub Category, Tag, and Description all help improve documentation and organization.
Input Parameters
This example is a basic GET API that requires an Employee Number as a parameter and will return some information about the employee and the office they are associated with.
You will notice that adding the :employeeNumber to the end of the HTTP path automatically added an employeeNumber parameter to the Input Parameters. These autogenerated path parameters can only be removed by changing the path. The default Type is string so we need to change it integer.
Double click on employeeNumber in the Input Parameters tab to open the Edit Parameter dialog
If you wish to use a query parameter instead of a path parameter or want to add additional parameters click the green plus sign in the Input Parameter panel to open the API Parameter dialog.
Fill in the following properties:
- Name: EmployeeNumber
- From: query
- Data Type: integer
- Check the Required checkbox
- Example: 1088
- Description: Employee Number to request data about
Adding a valid example and description makes testing the API easier and improves the autogenerated documentation.
Output Parameters
Switch to the Output Parameters tab and add the following parameters
Save
At this point you should save your API file by clicking the Save button in the menu ribbon. The first time you use save you will be presented a save dialog with the File Name defaulting to Unnamed.api.json. You should change the Unnamed portion to an appropriate file name, like Employee.api.json in this case. Click Save.
Add Low Code Logic
Click on Add Step... in the canvas.
In the What would you like to do? drop down expand the Database section and click on Retrieve One Database Record