SpringBoot e-commerce project mall (40K + STAR) address: github.com/macrozheng/…

Abstract

When using Swagger, do you have the feeling that the submitted parameter is JSON, it can’t be formatted, the wrong parameter can’t be found, the returned result can’t be folded, it’s too long to read! This situation has changed a lot after Swagger is used in combination with Postman. Today, we will talk about how to use Postman to enhance the function of Swagger, hoping to be helpful to everyone!

Postman used

Postman is a very useful interface debugging tool, beautiful interface and powerful, for those who do not know Postman, you can see Postman: API Debugging Tool.

Swagger is used in combination with Postman

Here’s how to import the Swagger API into Postman and use Postman to debug the interface.

Swagger API imports Postman

  • First we need to launch the application project that uses Swagger, here as the previous onemall-tiny-swaggerProject for example, findapi-docsPath, access address:http://localhost:8088/swagger-ui/

  • What’s Swagger’sapi-docsAccess path? This path returns JSON data, which is the source of all the Swagger API document pages in the application, and which Postman can use to render API document pages, as shown hereapi-docsThe address is:http://localhost:8088/v2/api-docs

  • Click on PostmanimportButton, selectLink, type Swagger’sapi-docsPostman = Postman; Postman = Postman; Postman = Postman;

  • You can use the default option to import it without modifying it.

  • After successfully importing Swagger, the interface in Swagger will appear in Postman, then you only need to change the parameters in Postman to start debugging interface, isn’t it very convenient!

Postman Sets environment variables

  • If we go to any random interface, we’ll find that the access is wrong becausebaseUrlThe environment variable was set incorrectly, causing the interface to be inaccessible.

  • We just set it up in PostmanbaseUrlThis environment variable can be accessed normally;

  • After adding environment variables, you need to select the environment before they are applied.

Access the interface that requires login authentication

  • When you visit the interface again, you will find that our interface needs login authentication to access normally.

  • We can first call the login interface to obtain the Token;

  • Add to the interface that requires login authenticationBearer TokenType of Token we can find need to configure a calledtokenEnvironment variables of;

  • Add to the environment variabletoken;

  • After adding environment variables, you can access the interface that requires login authentication.

What are the disadvantages

This approach is powerful for debugging interfaces using Postman, but a little weak for document presentation.

  • For example, the interface in Swagger has well-commented information about request and return parameters;

  • In Postman, however, this documentation is not reflected. Postman is still just an interface debugging tool.

conclusion

It is better to use Swagger and Postman together. Swagger is used to read interface document information, and Postman is used for debugging. Importing interfaces in Swagger into Postman can make up for the deficiency of Swagger in interface debugging.

Project source code address

Github.com/macrozheng/…

In this paper, making github.com/macrozheng/… Already included, welcome everyone Star!