Objective
Starting with the previous section, the following chapters will cover some of the tools used in the development process. As the saying goes, 工欲善其事, its prerequisite. For developers, there is a useful tool, but also a good thing, and the development is also very cool, the efficiency will be improved a lot. This section focuses on Postman
the HTTP impersonation request tool, which is typically tested for API interface services.
Aside: for the Postman
purposes of, I also just use a small part, or in line with the principle, for some of its advanced features, such as,, 自动化测试
auth认证
js脚本
and 生成各类语言代码(如cUrl、java、ajax等等)
, if used later, will write a blog post. Suddenly very feeling, to learn things really many Ah, so still that sentence: the spirit of enough on the line! Things are not to be learned!
- About Postman
- Installing postman
- Interface button Description
- Postman Testing a RESTful interface example
- Create a Web project
- Using the Postman test:
- Related information
- Summarize
- At last
- Cliché
About Postman
Postman is a powerful tool for debugging Web pages and sending HTTP requests to Web pages. Postman can send any type of HTTP request (GET, HEAD, Post,put.) with any number of arguments and HTTP headers. Supports different authentication mechanisms (basic, Digest,oauth), received response syntax highlighting (Html,json or XML). Postman can exist either in the form of a chrome plugin or as a standalone application. This article mainly explains the 客户端
use of.
Installing postman
Official website: Https://www.getpostman.com/apps
According to the actual operating environment, select the corresponding version of the download:
This article selects the current latest version directly: v6.2.2
.
After downloading, follow the prompts to install the default, this is not the map.
Interface button Description
The drawing is not easy, open from high School began to use Fireworks
. A program ape also needs to be plotted, (┬_┬). Not beautiful, the order is chaotic, let's see. What are you going to do!
1.History: Record history request records, generally all requests will appear on this panel, by date, click to quickly add a tab bar for the request.
2.Collections: Favorites. You can create the directory according to the type of request or project, which is easy to manage. Can create subdirectories, but also can be bulk requests, you can open a look, you should know the meaning
Internal button:
3. Sticky Notes page: You can toggle between different sticky notes pages for display.
4. Request method: such as GET, POST, delete, etc.
5. Request Address: The API address that needs to be tested or accessed, support variables, variable notation: {{param}},
6.URL parameter Value (QueryString): Sets the value of the parameter after the URL, such asauthor=okong&name=okong
7. Click to send the request while supporting the download.
8. Save the current request to collections and save it as a different collections. Next time you can quickly click.
9. Authentication parameters, such as, and OAuth
other protocols can be set OAuth2
.
10.HTTP Header: Custom request header information.
11. Request body (body) settings, such as the POST request, set the parameters of the request, or binary stream, JSON format parameters, XML format parameters, and so on.
12. Scripts executed before the request, such as the two random variables in the request body, are temporarily generated and unfamiliar, and are not used at this time.
13. The response test, the returned parameters are checked, and the result of the verification is displayed in the 19
function template. It's not used at the moment, skip it.
14. Cookies under each domain name are viewed and added:
15.code: You can generate request codes for different languages, such as Curl, Java, and so on with one click.
CURL:
Java: The Okhttp tool is used here
16, 17, 18, 19 are the request response response corresponding parameter values, should be more familiar with. such as the value returned, the cookie, the Header, the response test results, etc.
20. The status value of the request response, such as 200, as well as response time and size. Spit Slot: The entry-level server is slow. 200 Ms..
21. Copy the returned parameters to the Clipboard, which is the Ctrl+c
function, and can be pasted directly in other places.
22. Return parameters to query.
23. Return the different preview state of the parameter, is actually beautification.
24. Set up different workspaces, just like eclipse, which can vary the project workspace.
25. Set the variable value in different environment, just like the backend development has the test environment, the development environment, the joint adjustment environment and so on.
Postman Testing a RESTful interface example
With a simple Web service, the post, GET request example, others can install their own practice, self-clothed AH ~
Create a Web project
Here is a simple example of how to create a common HTTP request, such as GET, post, delete, put.
RestfulController.java
/** * 基于Postman的RESTfulAPI接口测试 * @author oKong * */@RestController@Slf4jpublic class RestfulController { @GetMapping("/get") public String get(String msg) { log.info("get方式!"); return msg; } @PostMapping("/post") public String post(@RequestBody String msg) { log.info("post方式!"); return msg; } @PutMapping("/put") public String put(@RequestBody String msg) { log.info("put方式!"); return msg; } @DeleteMapping("/delete") public String delete(String msg) { log.info("delete方式!"); return "delete " + msg + " success!"; } /** * 设置返回状态为417 * @param msg * @return */ @GetMapping("/status") @ResponseStatus(HttpStatus.EXPECTATION_FAILED) public String status(String msg) { log.info("status方式!"); return msg; }}
Using the Postman test
1.get mode:
2018-07-28 23:26:39.783 INFO 18092 --- [nio-8080-exec-5] c.l.l.s.chapter14.RestfulController : get方式!
2.post mode:
2018-07-28 23:29:00.143 INFO 18092 --- [nio-8080-exec-4] c.l.l.s.chapter14.RestfulController : post方式!
3.put mode
4.delete mode
5.httpStatus status test (set returned ResponseStatus
):
6. If the request is not in the correct manner:
At this point, you can save each request to the Collections
, you can test the next batch execution of the function run
.
Batch execution:
Console:
Related information
These explanations are relatively straightforward:
1.https://www.cnblogs.com/xiaoxi-3-/p/7839278.html
2.78574691
3. Official Document: https://www.getpostman.com/docs/v6/
Summarize
This chapter mainly explains the use of Postman
RESTful
interface style for testing, but also briefly introduces Postman
the simple usage. In my use process, the above several methods have basically met the development needs. The front also introduced Swagger
, in the docking of third-party system services, the Swagger
Basic is not on the use of, this time Postman
the role is reflected. Different scenarios under different test tools. As for some Postman
of the advanced usage, you need to search for the relevant information on their own, other features I was basically no use. (┬_┬)
At last
At present, many big guys on the internet have a SpringBoot
series of tutorials, if there is a similar, please forgive me. This article is the author in front of the computer word knocking, each step is practice. If there is something wrong in the text, also hope to put forward, thank you.
Cliché
- Personal QQ:
499452441
- Public Number:
lqdevOps
Personal blog: http://blog.lqdev.cn
Original address: https://blog.lqdev.cn/2018/07/28/springboot/chapter-fifteen/
Complete Example: chapter-15
Springboot | 15th: RESTful interface testing based on postman