SpringBoot系列: 与Spring Rest服务交互数据

不管是单体应用还是微服务应用, 现在都流行Restful风格,  下图是一个比较典型的使用rest的应用架构, 该应用不仅使用database数据源, 而且用到了一个Weather微服务, 另一方面, 该应用也是通过rest方式为web UI 或其他微服务应用提供服务. 

=============================
通过Postman 插件测试Rest接口
=============================

很多人使用postman 插件调试rest接口都报 415 Unsupported Media Type错误, 原因是: HEADERS中必须设置Content-type为application/json, 后台才能顺利接收到参数. 间下图截图. 
{
"timestamp": "2018-09-07T06:49:57.620+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'text/plain;charset=UTF-8' not supported",
"path": "/books"
}

=============================
Spring 后台与其他Rest服务的数据交互
=============================
Spring 提供了 RestTemplate 类, 方便和其他Rest服务交互数据

扫描二维码关注公众号,回复: 3096413 查看本文章

=========================
参考
=========================
https://www.leveluplunch.com/java/tutorials/014-post-json-to-spring-rest-webservice/
https://javabeat.net/rest-api-best-practices/
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
截图来自: https://github.com/hamvocke/testing-microservices-ebook/blob/master/testing-microservices.adoc

猜你喜欢

转载自www.cnblogs.com/harrychinese/p/Springboot_SpringRest.html