RestfulController.java
/** * 基于Postman的RESTfulAPI接口测试 * @author oKong * */ @RestController @Slf4j public 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; } } 使用Postman测试1.get方式:
2018-07-28 23:26:39.783 INFO 18092 --- [nio-8080-exec-5] c.l.l.s.chapter14.RestfulController : get方式!2.post方式:
2018-07-28 23:29:00.143 INFO 18092 --- [nio-8080-exec-4] c.l.l.s.chapter14.RestfulController : post方式!3.put方式
4.delete方式
5.httpStatus状态测试(设置返回的ResponseStatus):
6.请求方式不正确时:
此时,可以把各请求保存到Collections中,可以测试下批量执行的功能run.
批量执行:
控制台:
相关资料