HTTP API
Last updated
Was this helpful?
Last updated
Was this helpful?
In this article, we'll explore how you can without actually having to connect the data source or HTTP API data source. We will also review the data source's .
Without connecting your own HTTP API, you can still run your requests with UI Bakery. In this case, you simply need to create a new action, select the HTTP API data source, and the HTTP Request action will be selected automatically. After that, just specify the URL of your request directly in the action. This is the main required parameter for the action type.
You can also specify additional parameters which may be required depending on the API:
Method - the HTTP Request method (GET, POST, PUT, etc.)
Base URL - When a data source is connected to the action, Base API URL can be provided not to specify the whole URL for each action. You can change it once on the data source level for all actions.
URL - the URL or path of the API endpoint
Headers - the HTTP Request headers (string key-value pairs)
Body - For POST/PUT/DELETE/PATCH methods, you can specify the HTTP body as a JSON object or as plain text.
Query Params - the URL params added to the Request URL
Transform result toggle - You can pass a JS function to transform execution result or fix an error. The {{data}}
, {{error}}
, and {{res}}
variables represents the result of the request.
For example, you can pass a JSON object in the Body of your request by adding a Content-Type
header to it:
If your HTTP Requests share similar settings such as Base URL or Auth headers or your API requires authentication, you can configure your own HTTP API as a data source. To do so, follow the instruction below:
On the Data sources page, click Connect, and select HTTP API in the Data sources list.
Click Connect Datasource to save the configuration.
Please note that the settings defined on the data source level are sent from the back-end proxy and are not exposed to the front-end user.
Input
No specific input is required. The {data}}
and {{params}}
variables can be used to access the result of the previous step or incoming action's parameters.
Output
{{data}}
- API request result
{{error}}
- API request error
{{res}}
- full HTTP response object
UI Bakery also allows you to import API requests via cURL.
While creating an HTTP Request action, you can click the Import as CURL button and paste your command in the box. The system will fill in the configuration automatically.
Create an action, select your HTTP API data source and the HTTP Request action type.
Select the GET method and set the API URL, for example:
https://example-data.draftbit.com/users?_limit=5
Turn on the Transform result toggle and add a JavaScript function to modify the result:
Click Execute action and check the result.
Let's take look at how to send a form to make a POST API request:
Add the Form component to your working area.
Create a new action, select your HTTP API data source and the HTTP Request action type.
Select the POST method and set the API URL.
Next, click on the Body tab and change its format to JSON.
There, reference your newly added form as {{ui.myForm.value}}
.
Assign this action to the Form's On Submit trigger.
Fill in the Form, click Submit and check the result.
Now, whenever you click the Submit button, the action will be executed and the POST API request will be sent to the API.
Sometimes your API may return an error, for example, if a required field is missing or the value is incorrect. In such cases, you can open the Payload tab of the action and investigate header, url, body, and other parameters to check the data sent to the server.
If the HTTP data source server sets the cookies, these cookies will be passed for the subsequent requests to the server as well but will not be visible in {{res}}
.
You can locate them in the network tab of the Chrome dev tool for the request that was sent to execute the HTTP step.
Please note that to make the cookies work, you have to first.
If your API is hosted behind a Firewall, you need to add our to the Firewall whitelist.
Specify the Base URL and any additional parameters if necessary. To set up authentication, refer to .
Once you've established the connection to the data source, you can start interacting with its data via API. For this purpose, you can use the action step and configure HTTP parameters applicable to your API. UI Bakery supports all HTTP methods, Headers, Body, and Query Parameters.
You can learn more about data mapping .