Create your first Rest API

Creating a Rest API

API Gateway provides the ability to view, create, and manage REST APIs, and publish the APIs to a configured destination for consumption. This section describes how you can create your first REST API in API Gateway.

What is a REST API?

Representational State Transfer (REST) protocol defines a set of architectural principles that allow accessing and manipulating resources by using capabilities already built into HTTP using HTTP methods. The following are the key points of REST protocol:

Creating REST API using Import Option

In API Gateway, you can create REST APIs by importing it in two ways:

Creating a REST API by importing an API from a file

Before you begin

Ensure that you have

To create a REST API by importing an API from a file

Let’s look at a sample scenario, where you are creating a REST API by importing the SearchCruise file.

  1. Click APIs in the title navigation bar.

  2. Click Create API.

  3. Select Import API from file.

  4. Click Browse and select the SearchCruise.zip file.

  5. Click Open.

    Note
    If the Swagger parser is a self-contained file with no external references, you can upload directly. If the imported REST API file contains external references, the entire set of files must be uploaded as a ZIP file with a structure as referenced by the imported file. In such case, API Gateway displays the Root File Name field. Provide the root file name in the ZIP folder that you want to import. In this example, the root file name is SearchCruise.json.
  6. Provide the API name as Search Cruise in the Name field.

    • If you provide an API name, API Gateway overwrites the API name specified in the uploaded file.
    • If you do not provide an API name, API Gateway retains the API name mentioned in the uploaded file.
    • If you do not provide an API name and the uploaded file does not have an API name, the API name is displayed as Untitled.
  7. Provide the version number as 1.0 in the Version field.

  8. Select the type as Swagger since the imported Search Cruise API is a swagger file.

  9. Provide a description as Import search cruise API in the Description field.

  10. Select the team as Administrator for which you want to assign the Search Cruise in the Team field.

    Note
    This field appears only when the Team feature is enabled. It displays only the teams that you are a part of. If you have the User management functional privilege, all teams are displayed. You can select more than one team.
  11. Click Create. The Search Cruise API is created to search a cruise by cruise ID.

  12. Now that you have created the SearchCruise API, you can check whether it is imported properly by using any of the API testing tools. To know more about how to test the REST API using postman, see Testing REST API.

Next steps

Now that you have created the REST API, you must

Creating a REST API by importing an API from a URL

Before you begin

Ensure that you have

To create a REST API by importing an API from a URL

Let’s look at a sample scenario, where you are importing https://petstore.swagger.io/v2/swagger.json URL to create the Petstore REST API.

  1. Click APIs in the title navigation bar.

  2. Click Create API.

  3. Select Import API from URL.

  4. Provide the URL as https://petstore.swagger.io/v2/swagger.json

    Note
    As the provided URL is public, you do not have to select the Protected check box. If you have given the restricted access URL and if the URL is password protected, then you must select the Protected check box. After you select the Protected check box, API Gateway displays the Username and Password fields. Make sure you provide the login credentials of the given restricted access URL.

    Based on the specification used in the imported file, API Gateway auto populates the Type field. REST API supports the Open API, RAML,or Swagger specifications. As the https://petstore.swagger.io/v2/swagger.json URL is a swaggerfile, API Gateway, by default, selects the file type as Swagger.

  5. Provide the API name as Petstore in the Name field.

    • If you provide an API name, API Gateway overwrites the API name specified in the uploaded file.
    • If you do not provide an API name, API Gateway retains the API name mentioned in the uploaded file.
    • If you do not provide an API name and the uploaded file does not have an API name, the API name is displayed as Untitled.
  6. Provide the version number as 1.0 in the Version field.

  7. Provide the description as Import REST API using URL in the Description field.

  8. Select the team as Administrator for which you want to assign the Petstore API in the Team field.

    Note
    This field appears only when the Team feature is enabled. It displays only the teams that you are a part of. If you have the User management functional privilege, all teams are displayed. You can select more than one team.
  9. Click Create. The Petstore API is created with the following operations: a. Find purchase order in a pet store by Order ID b. Get the pet store’s inventory status

  10. Now that you have created the Petstore API, you can check whether it is imported properly by using any of the API testing tools. To know more about how to test the REST API using postman, see Testing REST API.

Next steps

Now that you have created the REST API, you must

Testing a REST API

Testing the imported REST API using Postman

You can test a REST API by invoking the REST API URI in postman. Specify the REST API URI with the required method in the format as follows:

You can customize or shorten the base path of the REST API URI by creating URL aliases. To know more about how to create URL aliases, see URL aliases.

Let’s test the SearchCruise REST API, which was imported using a file. In this example, to test whether the Search Cruise API is created successfully, let’s search a cruise with cruise ID 00001 using the Search Cruise API. The API response should include the details of the requested cruise.

To test the REST API using Postman

  1. In the Postman UI, select the http method as GET as the search is performed using the cruise ID.

  2. Invoke the endpoint, http://host_name:port_number/gateway/SearchCruise/10.2/cruises/{CrusieID}.

  3. In the Authorization tab, select the type as Basic Auth and provide the login credentials of the API Gateway instance.

  4. Click Send.
    The REST API is invoked successfully and returns the status code as 200. Also, the response contains the details of the Cruise.