For a complex web application, one page view might require data of many different types. If you are doing client-side templating and pulling in this data from a RESTful web service, you may have to make a lot of requests to populate the page. Is there any convention by which REST requests can be combined, to receive back a single payload containing all the responses needed?
To use the Stack Exchange User page as an example, you probably would need to call at least these from the Stack Exchange API to build the page:
Could the provider of such an API allow you a single request to get all that data? Especially if other root types were involved, say you had to also request /revisions/{id} and /tags to build the page also for some reason.
To be clear, I don't want to know if it's possible to provide such functionality in a web API -- I want to know if there is a standard or at least documented means of doing so.
When you provide JSON data as input for the create or update operations, the REST API takes into account only the properties that are writable on the element. The API ignores all other data. Read-only properties, such as computed counts or creation dates, are not updated. The API ignores unrecognized properties.
The REST API can handle multiple client requests by using the following methods: Using the asynchronous nature of HTTP: The client can make multiple requests to the REST API, and the REST API can handle those requests in an asynchronous manner.
If you need to make multiple API requests, you can send these API requests concurrently instead of sending them one by one. Sometimes, we need to make multiple API calls at once. For example, let's say we have an array, and we want to make an API request for each element of that array.
I think we need some standard way of doing this, but until then, you're probably on your own.
In the past I've had similar challenges when I wanted to do transactions spread across multiple resources. I invented new resources which described the actions I was about to make more clearly (subtracting 5 from account A and adding 5 to account B becomes a transaction with from and to members).
Maybe a similar (but more general) approach could be applied here by using another REST call as container;
POST /batchRequests { requests: [
{ method: 'POST', url: '/resource', payload: { ... } }
], transactional: false }
Which in turn returned a "BatchRequest" object containing results. It's pretty close to what Facebook did as well.
I think that might be against REST principles, no? i.e. the unique URI per object representation and its payload. Wouldn't it make things worse? Given that it's not TI calculator but a modern computer capable of parallel HTTP requests verses a single one that'll take as long as the logest of them all.
Don't think there is a standard, but here's an example -- https://developers.facebook.com/docs/reference/api/batch/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With