一、前言
公司内部的其他组件,提供了rpc、http服务,而 http 服务的组件,正打算测试以下接口的方法功能,无奈电脑没有安装 postman,却偶然发现 idea 自带 http 请求客户端,界面简洁美观,功能完善,完全不逊色于postman!
二、位置
打开idea左上方的菜单 Tools -> HTTP Client -> Test RESTful Web Service
打开后的界面如下
三、测试
简单写了一个get请求的接口
package com.cun.springboottest.controller;import com.cun.springboottest.domain.Student;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;import java.util.List;@RestController@RequestMapping("/student")public class StudentController { @GetMapping("/list") public List listStudent(){ ArrayList students = new ArrayList<>(); Student jd = new Student(1, "jd", 17); Student pdd = new Student(2, "pdd", 4); students.add(jd); students.add(pdd); return students; }}
测试请求:填写 method、host、port、path即可
复杂的场景,还可以在header里边增加参数,如最常见的 token等
可以看到,返回预期的结果!如此一来,又方便了开发测试了!