简体   繁体   English

对REST服务器的多个请求的模式

[英]Pattern for multiple requests to REST server

So let's say I have a typical REST server that serves some data in a very specific manner, like: GET accounts, GET prices, GET inventory, GET settings, GET user_history, etc... 假设我有一个典型的REST服务器,它以非常特定的方式提供一些数据,例如:GET帐户,GET价格,GET库存,GET设置,GET user_history等。

A single view, let's say, needs to fetch N different specific resources like this. 假设一个视图需要像这样获取N个不同的特定资源。 What's the best technique/library/pattern for combining N HTTP requests into one without too much hassle? 将N个HTTP请求组合成一个没有太多麻烦的最佳技术/库/模式是什么?

Maintaining the "REST" idea would require writing new server code for every view because no two views would need the same set of resources. 维持“ REST”的想法将需要为每个视图编写新的服务器代码,因为没有两个视图需要相同的资源集。 Doing this would become unnecessarily cumbersome in my opinion. 我认为这样做会不必要地麻烦。 I guess the only way that makes sense is to roll your own DSL that presents your data requirements to the server. 我认为唯一有意义的方法是滚动自己的DSL,以向服务器提出数据要求。

What's the easiest alternative to writing new response code for every possible combination of a given view's resource requirements? 对于给定视图的资源需求的每种可能组合,编写新的响应代码最简单的选择是什么?

You say this is a rest service, all you need to do is getting information, Why not issue a jsonp request? 您说这是一项休息服务,您需要做的就是获取信息,为什么不发出jsonp请求?

issue a jsonp request for every get that you need, instead of writing a new response code for each and every get. 为您需要的每个获取发出一个jsonp请求,而不是为每个获取编写新的响应代码。 It will save you alot of code and will enhance performance. 它将节省大量代码,并提高性能。

In conclusion, I would send a jsonp request to the server (given it's an external server of course) in order to get all the data that I need, while issuing ajax calls to the server. 总之,我将向服务器发送jsonp请求(当然,这当然是外部服务器),以便在向服务器发出ajax调用的同时获取我需要的所有数据。

issuing jsonp request to the same domain using .NET 使用.NET向同一域发出jsonp请求

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

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