HTTP API 服務
更新時間:
網關提供服務端 HTTP Demo 代碼供用戶下載測試,下載 API 提供者 Demo 后,HTTP Demo 代碼位置為:com/alipay/gateway/controller/http/MvcServerController.java。
重要
POST 請求的 Body 參數必須使用
@RequestBody
接收參數。Query 參數可以使用
@RequestParam()
接收指定參數,如果不使用 RequestParam,參數默認和請求參數名一致。
Demo 案例
/**
* 測試場景: 沒有參數的測試
*
* @return
*/
@RequestMapping(value = "/param/noParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> hello() {
return super.hello();
}
/**
* 測試場景:簡單參數
*
* @param param
* @return
*/
@RequestMapping(value = "/param/simpleParam", method = {RequestMethod.GET, RequestMethod.DELETE})
@ResponseBody
@Override
public String simpleParam(@RequestParam("param") String param) {
return super.simpleParam(param);
}
/**
* 測試場景:簡單參數
*
* @param param
* @return
*/
@RequestMapping(value = "/param/simpleParam", method = {RequestMethod.POST, RequestMethod.PUT})
@ResponseBody
public String simpleBodyParam(@RequestBody String param) {
return super.simpleParam(param);
}
/**
* 測試場景:簡單參數
*
* @param param
* @return
*/
@RequestMapping(value = "/param/simpleParamForMap", method = {RequestMethod.GET, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> simpleParamForMap(@RequestParam("param") String param) {
return super.simpleParamForMap(param);
}
/**
* 測試場景:簡單參數
*
* @param param
* @return
*/
@RequestMapping(value = "/param/simpleParamForMap", method = {RequestMethod.POST, RequestMethod.PUT})
@ResponseBody
public Map<String, String> simpleBodyParamForMap(@RequestBody String param) {
return super.simpleParamForMap(param);
}
/**
* 測試場景:簡單參數
*
* @param param
* @return
*/
@RequestMapping(value = "/param/intParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Integer intParam(Integer param) {
return super.intParam(param);
}
/**
* 測試場景:多參數
*
* @return
*/
@RequestMapping(value = "/param/multiParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> multiParam(@RequestParam("param1") String param1,
@RequestParam("param2") String param2) {
return super.multiParam(param1, param2);
}
/**
* 測試場景:多參數
*
* @return
*/
@RequestMapping(value = "/param/multiParamList", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> multiParamList(@RequestBody List<String> params) {
return super.multiParamList(params);
}
/**
* 測試場景:路徑參數
*
* @param uid
* @return
*/
@RequestMapping(value = "/param/{uid}", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> pathParam(@PathVariable("uid") String uid) {
return super.pathParam(uid);
}
/**
* 測試場景:json參數
*
* @param user
* @return
*/
@RequestMapping(value = "/param/jsonParam", method = {RequestMethod.POST, RequestMethod.PUT})
@ResponseBody
public User jsonBodyParam(@RequestBody User user) {
return super.jsonParam(user);
}
/**
* 場景:獲取cookie|header|query 內容
*
* @param request
* @return
*/
@RequestMapping(value = "/param/withHeader", method = {RequestMethod.POST, RequestMethod.PUT})
@ResponseBody
public Map<String, String> withHeaderBodyParam(HttpServletRequest request, @RequestBody String name) {
return super.withHeader(request, name);
}
/**
* 場景:獲取header 多參數共傳
*
* @return
*/
@RequestMapping(value = "/param/moreParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, Object> moreParam(@CookieParam("param") String param, @HeaderParam("userName") String userName, @QueryParam("age") String age) {
return super.moreParam(param, userName, age);
}
/**
* 場景:模擬超時
*
* @param param
*/
@RequestMapping(value = "/timeout", method = {RequestMethod.GET, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> timeout(@RequestParam("param") String param) {
return super.timeout(param);
}
/**
* 測試場景:測試緩存
*
* @param param
* @return
*/
@RequestMapping(value = "/param/cache", method = {RequestMethod.GET, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> cache(@RequestParam("param") String param) {
return super.cache(param);
}
/**
* 測試場景:外部授權body傳參
*
* @param param
* @return
*/
@RequestMapping(value = "/param/authBodyParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, String> authBodyParam(String param, HttpServletRequest request) {
return super.authBodyParam(param, request);
}
/**
* 測試場景:請求參數映射
*
* @param
* @return
*/
@RequestMapping(value = "/param/requestParamMapping", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public List<JSONObject> requestParamMapping(HttpServletRequest request, @RequestBody List<JSONObject> jsonObject) {
return super.requestParamMapping(request, jsonObject);
}
/**
* 測試場景:響應參數映射
*
* @param
* @return
*/
@RequestMapping(value = "/param/responseParamMapping", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public JSONObject responseParamMapping(HttpServletRequest request, @RequestBody List<JSONObject> jsonObject) {
return super.responseParamMapping(request, jsonObject);
}
/**
* 測試場景:LDC路由
*
* @param
* @return
*/
@RequestMapping(value = "/param/ldc", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, Object> ldc(HttpServletResponse response, HttpServletRequest request) {
return super.ldc(response, request);
}
/**
* 測試場景:返回 Object 有參數
*
* @param
* @return
*/
@RequestMapping(value = "/param/objectSimpleParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Object objectSimpleParam(@RequestBody User user) {
return super.objectSimpleParam(user);
}
/**
* 測試場景:返回 Map 有參數
*
* @param
* @return
*/
@RequestMapping(value = "/param/mapSimpleParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public Map<String, User> mapSimpleParam(@RequestBody Map<String, User> map) {
return super.mapSimpleParam(map);
}
/**
* 測試場景:返回 List 有參數
*
* @param
* @return
*/
@RequestMapping(value = "/param/listSimpleParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public List<User> listSimpleParam(@RequestBody List<User> list) {
return super.listSimpleParam(list);
}
/**
* 測試場景:返回StringOutput StringInput參數
*
* @param
* @return
*/
@RequestMapping(value = "/param/stringInputParam", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@ResponseBody
@Override
public StringOutput inputParam(@RequestBody StringInput input) {
return super.inputParam(input);
}
文檔內容是否對您有幫助?