Connect to Rest API

Learn Datasources: Rest API with Kuika.

REST API (Representational State Transfer Application Programming Interface) is a protocol that facilitates data communication between applications. Using REST APIs, one application can receive data from or send data to another application.

Let's assume you have a weather application. You need to get weather data from an external service. Using this service's REST API, you can pull the weather data.

For instance, you can use the following URL to get weather data: https://api.weather.com/current-weather?city=Ankara.

When you open this URL in a browser, you receive a response returning the weather data. In your application, you can use this API to pull the weather data and present it to the user.

In this way, you can facilitate data exchange between different applications using REST APIs.

For an application you develop in Kuika, you can connect it to a Rest API as a data source.

When developing an application with Kuika, you can use various data sources. One of the data sources you can use is the Rest API. You can quickly connect a Rest API you own to an application you develop in Kuika.

To create a Rest API in Kuika, click on the Datasource view mode in the Header within the application.

In the Datasources view mode, you can view the data sources, actions, and tables in the application you developed on the left. You can add a new data source, a new action, and a new table.

In the Datasources view mode, click the + icon on the left. In the screen that opens, select REST API and name it, then click the Create button.

On the user screen that opens, you can click on the field where the name given to the API is written at the beginning to change the name. In the top right corner, there is a Description area where users can keep notes about the API.

The Connection Settings page contains fields where the API's connection and authentication settings are made. To set the connection settings of the API, the URL provided by the API service must be entered into the Service Base URL field.

Sample API URL: https://petstore.swagger.io/v2

(For API Documentation: https://petstore.swagger.io/)

The service base URL of an API is provided by the API provider and can be found on the provider's website.

For setting up authentication, one of the options from the dropdown menu under Authentication Type titled No Auth, Bearer, or API Key must be selected.

1. No Auth

If No Auth is chosen as the authentication type, there is no need for any configuration.

Excluding No Auth, parameters are created for Bearer and API Key options. There are three types of parameters that can be created: Query String, Path, and Header.

Query String:

  • A Query string starts at the end of the URL with a "?" and contains one or more key-value pairs. Example: https://www.example.com/api/endpoint?param1=value1&param2=value2

  • After the "?" sign, each key is separated from its value with an "=" sign, and different key-value pairs are separated by an "&" sign.

  • Query strings are typically used for operations like filtering, sorting, or querying.

Path:

  • Path parameters refer to the portion of the URL following the base domain, representing resources in a particular structure. Example: https://www.example.com/api/users/123/profile

  • Path parameters define parts of the URL where endpoints or resources are accessed in a specific manner.

  • They are usually used for reading, updating, or deleting data operations.

  • Header parameters carry additional information in HTTP requests or responses and usually come as key-value pairs.

2. Bearer:

  • Bearer authentication is used by a client (typically an app or user) to prove their access authority to a server.

  • This is a method commonly used in OAuth 2.0 and other authentication protocols.

  • In Kuika, when Bearer is selected from the Authentication type dropdown, parameters come with Custom and Username.

  • During the parameter addition process, Kuika creates a value for the Username parameter by default. To add custom parameters, enter parameter information as a Key and Value Pair using the Custom option.

The Bearer authentication method works as follows:

  • A client (e.g., a mobile or web app) sends a request to a server when authentication is required to access it.

  • The server detects the client needs authentication and generates an access token. This token is an authorization code allowing the client to access server-side resources.

  • The server gives the access token to the client. This access token is referred to as a Bearer Token.

  • When the client wishes to access server-side resources, it authenticates using the Bearer Token by transmitting it to the server in the header section of the HTTP request using the Authorization header. The Bearer Token is sent separated by a space after the word Bearer.

3. API Key

An API Key (Application Programming Interface Key) is an authentication mechanism used to secure and monitor application development processes using an API.

When API Key is selected from the Selectbox, it comes with the options Custom, Username, and Auth Token.

In the Authentication Type field, when the API key is selected, the Client ID Key Name, Client ID, Client Secret Key Name, and Client Secret fields must be filled in to use this type of authentication.

  • Client ID Key Name: This is the key name used in the API request header.

  • Client ID: A unique identifier that defines an app or user.

  • Client Secret Key Name: This is the name of the secret key used in the API request header.

  • Client Secret: A secret key that needs to be kept secure and is used to validate the Client ID.

After entering the necessary information, proceed with the parameter addition process. During this process, Kuika creates a value for the Username parameter by default. To add custom parameters, enter the parameter details as a Key and Value Pair using the Custom option.

After entering all necessary information and parameters, click the Create button. Following this, the Rest API will be redirected to a new screen.

Rest API EndPoint:

An API Endpoint is an accessible URL or URI (Uniform Resource Identifier) address that represents a specific functionality or resource of a web service (API). The endpoint allows an API to communicate with the outside world and execute a particular resource or operation.

The Rest API EndPoint screen includes categories such as Parameters, Authorization, and Body.

On the Parameters screen, you can create parameters for the API with fields like Key, Value, Location, and Type.

In the Authorization screen, under Authentication Type, options like No Auth, Bearer, and API Key are available, similar to what's in the Rest API.

Additionally, there is the Inherit From collection.

If Inherit From collection is chosen from the dropdown menu, the parameters defined within the Rest API are used.

The Body screen displays the returned values in the created HTTP requests.

GET: Used to retrieve data and does not send data to the server.

POST: Used to send new data to the server, with the data being transmitted in the body of the HTTP request.

PUT: Used to update existing data or create new data.

DELETE: Used to delete the resource at the specified URL.

For GET and DELETE, since there's no returned field, the Body area is displayed as read-only.

The Body screen consists of two main sections, namely the Request Body and the Response Body.

Request Body is a part of an HTTP request. It contains the data or content of a request sent by a client to a server.

Response Body returns after completing a web request if it's successful, containing various types of data depending on the purpose of the request.

When you want to define any new Endpoint in the Datasource, click on the + icon located next to Actions under the Created RestAPI. You can create a new Endpoint by selecting New Rest API Endpoint.

On the Rest API Endpoint screen, HTML methods are selected, and the path is written. The API URL appears written on the opened screen.

Rest API Integration:

Let's examine the Rest API integration in Kuika with the API URL https://petstore.swagger.io/v2.

First, click on the Datasource view mode. Then click on the + icon and select Rest API. Name it PetRestApi.

Next, click on the Create button.

Enter the API URL https://petstore.swagger.io/v2 into the Service Base URL field. Select the Authentication Type as No Auth.

Then, click on the Create button again.

The Rest API Endpoint screen will open. On this screen, you can integrate the endpoints of the API as actions into your project. When adding API endpoints, you should refer to your source code or any available documentation (e.g., https://petstore.swagger.io/v2).

On this page, select the HTTP method you want to add from the dropdown, making sure to exclude the " / " prefix. This is because " / " is predefined in Kuika.

For example, to use the GET method, copy /pet/findByStatus and add it to where items is written, excluding the " / " prefix.

If the Rest API you want to integrate uses any parameters in its endpoint, you should add them here.

To create a parameter, click on the Add field.

After the parameter is created, click on the Run button.

The Rest API and parameter were successfully created.

The created Rest API will be displayed on the left pane with its HTTP method.

You have successfully performed the Rest API operations.

Last updated