Knowledge comb: Postman basic use of detailed explanation

background

Postman is a Google Chrome plugin designed to debug and send HTTP requests to web pages, and to run test cases. Its main functions include:

Simulate various HTTP requests

From common GET and POST to RESTful PUT and DELETE… And so on. You can even send files and send extra headers.

Collection functionality (Test Collection)

A Collection is a Collection of requests, and when you’re done with a test, you can save that request to a specific Collection so that you don’t have to re-enter it the next time you run the same test. Moreover, a collection can contain multiple requests. If we regard a request as a test case, a collection can be regarded as a test suite. Through the classification of collection, we can classify the APIS provided by the software. Collections can also be imported or shared to allow everyone on the team to Share the Collection you have created.

Humanized Response arrangement

When testing with other tools, the response content is usually raw text, but if it is JSON, it is stuffed into a full line of JSON. This makes reading difficult, and Postman can automatically beautify the format of the response. JSON, XML, or HTML are organized into a format we can read

Built-in test scripting language

Postman supports writing test scripts that can quickly check the results of a request and return test results

Set variables and environment

Postman can set variables and Environment freely. Generally, when we edit request and verify response, we always need to input some characters repeatedly, such as URL. Postman allows us to set variables to store these values. And keep variables in different environments. For example, we could have multiple environments, like development, staging, or local, and the request URL would be different in each of those environments, but we could set the same variables in different environments, just at different values, so that we didn’t have to change our test script. And test different environments.

Postman Important note:

Since Chrome stopped supporting Chrome apps in early 2018, your Postman plugin may not work properly. Right now the Chrome App Store is all about Chrome extensions and theme backgrounds. I suggest you download the app directly to use it

  • Download address

    • Download address: www.postman.com/downloads/

    • The following way fool installation can be

      • After the installation, the following interface is displayed
    • Personal operation habits, set the theme to black

The operating environment

Postman supports various operating systems, including Postman Mac, Windows X32, Windows X64, and Linux. Postman also supports postman Browser extensions and Postman Chrome applications.

Basic functions of Postman

Postman sending requests

Once installed, open Postman and you can see that the interface is divided into two parts, the left side is the Collection, and the right side is the Request Builder. In the Request Builder, Postman can be used to quickly assemble any request we want. Generally speaking, all HTTP requests are split into four parts: URL, Method, headers, and body. Postman has targeted tools for each of these.

URL

To assemble a Request, the URL is always the first thing you need to fill in. In Postman, urls that you have entered can be automatically completed by pull-down. If you click on the Params button, Postman will bring up a key-value editor where you can enter the Parameter of the URL, and Postman will automatically add it to the URL for you. On the other hand, if your URL already has parameters, Postman will load the parameters automatically when you open the key-value editor.

Method

Postman supports all methods, and once you select a Method, the Postman Request Body editor automatically changes based on your selection.

Request area details

  • Postman also has helpers that help us simplify some repetitive and complex tasks. The current set of helpers can help you resolve authentication Protocols issues.

  • Headers: Header information for the request. Clicking on the ‘Headers’ button will also bring up a key value editor for Postman. Here, you can add any Header attribute you want, and Postman does a nice auto-complete for us, where you type in a letter, and you can select the standard Atrribute you want from the drop-down menu.

  • Body: a mandatory parameter for a POST request, containing key-value pairs

  • Pre-requerst Script: Allows you to customize the request data before the request is made. This runs before the request and uses JavaScript syntax.

  • Tests: The Tests tag is quite powerful and is usually used to write tests that are run after the request. Support for JavaScript syntax. Postman executes tests every time it executes a request. The test results will be displayed on the Tests TAB with the number of passes and whether they were correct or wrong. This will be discussed later, but it can also be used to design use cases, such as to test whether the result returned contains a certain string

  • Form-data: It processes form data into a message, grouped by labels and separated by delimiters. You can upload key-value pairs separately or upload files directly. (If the upload field is a file, the content-Type is used to specify the file Type **, but the file is not saved as a history ** and can only be re-added each time a request is sent.

  • X-www-form-urlencoded: corresponding header -application/ X-www-from-urlencoded, will convert the data in the form into key-value pairs;

  • Raw: You can upload any type of text, such as text, JSON, XML, etc. All the filled text will be sent with the request.

  • Binary: uploads only binary files without key-value pairs, uploads only one file at a time, and uploads only one file at a time.

In response to the sample

The response status code, response time, and response size of the request.

Sample response body

The response can take many forms.

A GET request

Click Params after the URL and enter a parameter and value. You can enter more than one parameter to bind the parameter to the url.

GET can omit the request header.

There are three types of response bodies: JSON, HTML, and XML. Normally, a custom interface returns a response body in JSON format.

A POST request

POST request testing is divided into four main parameter submission methods: form submission; JSON submitted; XML submission; Binary commit.

  • There are two ways to submit a form:
    • Multipart /form-data (you can upload binary data, such as files, as well as form key-value pairs, which will eventually be converted into a message)
    • X-www-form-urlencoded (only key-value pairs can be uploaded, and key-value pairs are spaced apart)

Manage use case Collections

Collections: That is, multiple interface requests can be put together and managed. One Collection for each project, so that it is convenient to find and process data uniformly.

The first step is to create Collections

Click on the + sign icon in the image above, enter Name: “ABC”, Description: “Sample demo”, and click the Create button to Create a collection.

The second step is to add requests to Collections

After all the data for the interface request is ready and validated on the right, click the Save button.

Export and import interface sets:

Postman supports a very convenient set of import and export interfaces. Continue as follows:

export

Import:

  • Ok, this is a simple import/export collection collection

Authentication Authentication

  • Basic Auth

    • For basic authentication, the user name and password are directly added to the Header of the Request. Enter the user name and password, and click Update Request to generate the Authorization Header.
  • Digest Auth

    • Digest Auth extends security over basic AUTHENTICATION. The server generates a unique random number for each connection. The client uses this number to encrypt the password using MD5 and then returns the password to the server. It is then compared with the encrypted data sent from the client and returns the result if it is consistent. Generate the Authorization Header using the current value. So make sure your Settings are correct before you generate the header. If the current header already exists, Postman removes the previous header.
  • The 1.0

    • Postman’s OAuth Helper supports OAuth 1.0 and is authenticated based requests. OAuth does not require access tokens, you need to go to the API provider to obtain them. OAuth 1.0 can set value in header or query parameters.
  • The 2.0

    • Postman supports getting OAuth 2.0 tokens and adding them to Requests. This kind of authorization method is very common, all kinds of third party logins are authorized with OAuth 2.0.