美文网首页
了解RESTFUL API原理及实现

了解RESTFUL API原理及实现

作者: 沉思的老猫 | 来源:发表于2017-09-22 11:31 被阅读0次

一、原理

API:接口,适用于app、h5、c#等开发。

RESTful:一种软件架构风格。

解决问题:

1.提供了一组设计原则和约束条件,是一种规范。

2.便于后期维护。

3.规避安全性问题

4.结构简洁,层次清晰。

5.易于扩展,实现缓存等机制等,从而提高性能。

二、实现

spring  RestTemplate 

HttpHeaders requestHeaders =newHttpHeaders();

MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");

requestHeaders.setContentType(type);

HttpEntity entity =newHttpEntity(paramJson.toJSONString(), requestHeaders);

ResponseEntity entitymap =newRestTemplate().postForEntity(url, entity, JSONObject.class);

github HttpRequest

String body = HttpRequest .post(url)

   .contentType("application/json")

   .send(paramJson.toJSONString())

   .body();

相关文章

网友评论

      本文标题:了解RESTFUL API原理及实现

      本文链接:https://www.haomeiwen.com/subject/pkoxextx.html