Pagination of Large Computed Responses #41
-
|
I wanted to have a discussion around what we feel is the best way to handle returning potentially large responses that are computed as opposed to just reading from a large collection of objects. Simply paginating these requests can be tricky, as the computation is sometimes expensive and would require rerunning it whenever the users calls in with a new page seems like it could add up rather quickly. After some smaller discussions, it seemed like we were able to determine the following possible solutions:
What are our general thoughts around this idea and how would we like to generally define this behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
@jlnaps, could you please provide some examples for the use case? |
Beta Was this translation helpful? Give feedback.
-
|
@jlnaps it sounds like you're talking about an "action" style, non-restful endpoint that needs to return a collection? If so, then I think the answer largely depends on your implementation and less on the standards. Generally speaking, if you can pivot to think about the action as a Keeping it action style endpoint is less desirable, but largely something you'd need to decide on your design. Keeping it as action style endpoint might infer that this is not something that you can page through, give all the results. I'd almost suggest that if pagination is needed, that you consider moving to more restful style, which might involve more async behavior where you get an ID, its processed in the background and then results can be paged through RESTfully. |
Beta Was this translation helpful? Give feedback.
@jlnaps it sounds like you're talking about an "action" style, non-restful endpoint that needs to return a collection?
https://spscommerce.github.io/sps-api-standards/standards/url-structure.html#actions
If so, then I think the answer largely depends on your implementation and less on the standards.
Generally speaking, if you can pivot to think about the action as a
nounwith its own resource, then you can apply the API Standards much more closely. This would imply shifting/users/{id}/activateto something more restful like/users/{id}/activations/where activation is now a proper collection that. Of course, as a proper collection, you would need to provide a performant way to continuall…