With the release of version 7.1 of Postman, they have introduced the most anticipated feature in the API development and testing industry, that is, the ability to create an API in Postman itself. It will certainly make their position more concrete in the market. Moreover, we can use this feature for testing and development purposes.
In this tutorial, we will learn how to create an API in Postman. Additionally, we will also understand features like creating the documentation of API, monitoring the API, and hitting the API through a mock server. Currently, in the Beta phase, as indicated by the company, this feature is getting improved every day by the feedbacks and performance as time passes by. To understand this tutorial, the user must be familiar with the following topics:
- What is an API? (Refer Link)
- Collections In Postman (Refer Link)
- Mock Servers in Postman (Refer Link)
Introduction to Schema Support For API Creation In Postman
Postman has introduced the creation of API features. Moreover, calling its backbone as “complete schema support for creating the APIs.” A schema in general computer science terms means an outline or a structure of something. Even though it is used primarily for the database.
In Postman terms, it means creating the structure of the API. That is to say, what parameters and different values it will contain. The schema support in Postman helps the user to create their APIs, edit these APIs, or import the schema from outside Postman like your local machine. The main reason for using the schema support is that the user can escape the usage of different tools to perform these operations. Moreover, the user can make use of single software for all of the tasks, which is Postman. This feature has launched for RAML, WADL, and OpenAPI types.
The API Tab In Postman
Postman has introduced an all-new tab for availing the benefits of this feature. This tab is located just beside the History and Collection Tab, as shown in the image below:
Selecting this tab will open up the complete workspace for dealing with the APIs. But, remember that this feature is currently available only for the account holders in Postman. Therefore, the user needs to sign in to the application to enjoy creating the APIs.
Select New API or Create an API to open up your first workspace.
This workspace will contain tons of options that are hard to discuss in one post. Therefore, let’s briefly talk about the four primary tabs in this workspace.
These four options are the stepwise process for developing a complete API. Although we don’t have to use them all together. But, it depends on the user’s requirements.
1. Define: The first option creates the schema of the API. We will see this in the next section subsequently. In addition to that, the user can also import schema from somewhere else to work on it by themselves.
2. Develop: Secondly, the develop option provides additional API features that we have already discussed in the course. Through this option, a user can add the endpoint to the mock server, create and publish documentation for the API. Additionally, the user can also play with the environment to switch between different setups without changing the request.
3. Test: The test tab provides a variety of testing options for the tester to develop a spotless and great API. It includes creating a new test suite to test the API behavior, performing integration testing on the API to check if the API works well with the third-party applications or not. Additionally, contract tests to make sure that the API works according to its specifications.
4. Observe: Fourthly, monitor the performance of your API under various conditions and intervals with the help of Postman Monitors.
To conclude, these tools come pretty handy for developing a complete packed API according to the user’s need. So, let’s create our very first API in Postman.
Creating an API in Postman
In this section, we will create an API in Postman. We recommend the user to read and understand the structure of OpenAPI specification first. Because it will be beneficial in understanding how the API is working. The user can also take help from third-party applications such as Swagger to create their APIs within seconds.
In this tutorial, I have created an API specification for your use. It is on the guidelines of OpenAPI specifications. Additionally, it is about searching the origin of a flight. Although this is a basic API, it’s primary purpose is to increase your understanding of Postman.
1. Go to the Define tab as shown in the previous section.
2. Click on Untitled API to rename the API to a meaningful name.
3. Click on Add Schema dropdown and select Create new to create a new schema.
4. Select Open API 3.0 if it is not selected by default.
5. Copy and Paste the following API code:
openapi: 3.0.0
info:
description: This is a simple API of ToolsQA
version: “1.0.0-oas3”
title: Flight Info API
paths:
/origin:
get:
summary: searches origin of flight
parameters:
– in: query
name: searchString
description: Query about the origin of the flight
required: false
schema:
type: string
responses:
‘200’:
description: search results matching criteria
‘400’:
description: bad input parameter
6. In addition to the above, change the format from JSON to YAML to remove the error.
7. Save the API by clicking the Save button.
8. Finally, the schema will add, and you will get a notification.
9. To work upon this API, we need a collection. Thankfully, Postman does that with just a click of a button. To generate the collection, click on Generate Collection.
10. Give an appropriate name to the collection and generate the collection by clicking generate collection.
11. Visit the Collections tab and the collection will be visible under it.
12. After that, a request will be automatically generated under the collection. Just click the collection to view the request.
13. In the builder section of Postman, the API will be designed for you with the parameters shown.
Note: To know more about the different sections of Postman and parameters, you can visit Postman Navigation.
Consequently, this way, we can create a new API within minutes. Although this does not build you the final API through which you can get a response. Because, for that, you would need a server. The user can go ahead and set up their framework and code a little to get a response. Moreover, one can also achieve Dummy responses through a mock server (Develop Section). For now, Postman is gaining speed in this process and is aiming to make it a complete package from where users need not migrate to a different website to achieve the task. It would take some time, though. But, as a first step, it is excellent and commendable.