Connect and consume: Master the art of consuming REST APIs

Reading time: 4 minutes

APIs are created so that users can use them as a bridge to connect to applications and services. Thousands of APIs are available for consumption, and each API is unique. But it’s really easy to consume APIs to extend the capabilities of your Linx solutions, even complex ones that require OAuth 2.0 tokens. Let us show you how with a real-life example.

 

 

Steps to Consume and API

 

  1. Find the API you want to use. APIs can be categorized as Open APIs, Partner APIs or Private APIs. Open APIs are available to the public, whereas Partner APIs are offered to business partners (no public access). Private APIs are designed for internal use.
  2. Request access to consume the API. Each API service has its authorization method. To grant access to use an API, credentials are provided to users for use.
  3. View the API reference documentation or guidelines on how to consume the API. The API documentation will provide endpoints with their respective details, including
    – The URL (endpoint) of the operation
    – Request authentication
    – Request parameters (such as query values, body etc.)
    – Response data object.

 

 

We’ve used the pet store API sample hosted at https://petstore3.swagger.io as an example to show you how Linx can be used to consume APIs from a REST Service.

Try it! Download the Petstore sample solution

 

How to Call a REST Service in Linx

In the following example, we’ll call the method findByStatus. We’ll break it down into 4 parts as above.

1. The URL (endpoint) of the operation

2. Request Authentication. For this test, the default api-key ‘special-key’ was used.

3. Request parameters

4. Response Data Object

 

 

Build!

 

Once you have gathered all the information, you can build the app to consume the above endpoint. Linx provides an easy way to consume REST APIs using the CallRESTEndpoint Plugin

  1. Drag and drop the CallRESTEndpoint on the designer canvas.
  2. Choose the Authentication type.
  3. Fill in the information about the URL.
  4. Choose Method.
  5. If the REST API you are consuming requires specific headers or uses HTTP Authentication, fill in the necessary information.
  6. Fill in the information about the Body. If you choose JSON as the body format, you can use the Custom Linx Type to build the JSON structure. Check the API documentation to get complete details for body fields.
  7. Choose the Response Output Type. Check the API documentation to get complete details for response fields.

 

Now you can start sending requests to the API. Run Linx in Debug Mode to test the API.

Further reading: Debugging a Linx Solution

Low-code API development guides

  • Design-first: Build an API using an OpenAPI specification
  • Code-first API builder:  Use Linx for quick API implementation, including hosting and documentation 

Sign up to our Newsletter