简体   繁体   English

在Java中使用REST API有哪些不同的用例

[英]What are the different use cases for using REST API in java

I have an use case where i need to use rest api to call other system to get some data, as per my understanding i have created a flow of request and things which will be required. 我有一个用例,我需要使用rest api来调用其他系统以获取一些数据,据我的理解,我创建了请求流和所需的东西。 But just not sure whether it is right approach. 但是只是不确定是否正确的方法。

My UI has some input parameters based on which my rest api will fetch data from external system. 我的UI有一些输入参数,其余的api将根据这些输入参数从外部系统获取数据。

UI --> ManagedBean(Mapped to UI)-->Service Layer-->Business Layer-->Rest API Layer(i format my rest url, and other inputs required here) --> Calls MyCustomController(Implemented using SPring MVC), this will return JSON format data to the Business layer. UI-> ManagedBean(映射到UI)->服务层->业务层-> Rest API层(我格式化我的剩余URL和其他所需的输入)->调用MyCustomController(使用SPring MVC实现) ,这会将JSON格式的数据返回到业务层。

So whenever i call RestTemplate.executeService() --> i am calling controller to intercept this incoming request and it will fetch data from external system. 因此,每当我调用RestTemplate.executeService()->时,我都会调用控制器来拦截此传入请求,并且它将从外部系统获取数据。

Is it right approach? 这是正确的方法吗?

If you want to expose a service to your consumer then providing a web service is a better option. 如果您想向用户提供服务,则提供Web服务是更好的选择。

Multiple ways to develop web service SOAP, REST, etc. 开发Web服务SOAP,REST等的多种方法

I find REST light weight, intuitive, easy to implement compared to SOAP. 与SOAP相比,我发现REST重量轻,直观,易于实现。

In your case you said JSON format data to business layer. 在您的情况下,您说的是JSON格式的数据到业务层。 I believe you will be marshalling that into JAVA object for ease of use and good practice. 我相信您会为了方便使用和良好实践而将其编组到JAVA对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM