-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: improvements to rest#request #103
Comments
The problem with the suggested alternatives is that they require the called API to conform to certain conventions. The point of I do agree that this leads to an API that's really awkward to use. Should we specify that something like the existing API is still available (maybe |
I agree that We could mandate that |
but then that further violates the principle:
|
If we change the rest api so drastically that we break the (my second proposal doesn't involve the client lib making any assumptions about a batchresponse, since it just returns that as the regular array response body and gets rid of the nested batch-response-includes-errors error response) But, ok, if we did really want to leave rest#request with its current semantics (which does have the advantage of avoiding having to figure out how we do backcompat), then per Lewis's suggestion we can add a new rest#requestBatch with saner semantics (but which makes stronger assumptions about realtime conventions), sure. rest#request would continue to exist, but at least we'd have requestBatch that we can recommend for use with bulk publish, bulk presence get, token revocation, etc. |
How about:
So we are changing the semantics of |
That would be a sufficiently breaking change that we couldn't really do it except with a client lib major version change (since people use rest#request now for things like bulk publishing). And.. yeah, we'll need to figure out how to do that sooner or later. But realistically it would be towards the 'later' end. Maybe introduce Also though.. the only reason for having (Is the argument 'you need to know whether it's an object or array to know how to do something with it'? If so I'm sceptical. If you want to interact with it programmatically you really need to know the detailed response type for that api call, which you'll look up in the documentation. I don't see why having the method assure you that "it's an array of something" is really any more useful than knowing 'it's something, which might be an array of other things'). |
Hi 👋 - sorry that I've not got around to engaging on this one yet. I'm planning to look at it next week. |
Loosely related to #32 |
@QuintinWillison gently bumping this up your todo list |
Sorry, this is still on my (long) list of things to look at. I want to take a closer look at how this has been implemented across a few client libraries in practice, how that differs (or not) from other APIs in that library and to draw some diagrams to ensure my understanding is complete. I also want to investigate whether the spec has too much overreach in each case, in respect of how it mandates the shape of client library APIs (Ably vs language/platform-idiomatic conventions). |
I think we should consider this for 2.0 -- we've already committed to make one change to the |
➤ Automation for Jira commented: The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-2844 |
NB: we've already done the 'we can change the realtime response...' part of option 2 as part of the new batch response #139 . So option 2 is looking pretty good |
The design of rest#request (with the HttpPaginatedResource), introduced in 2016 in ably/docs#133 , is quite weird.
Having error messages primarily exposed as res.errorMessage & res.errorCode is inconsistent with how every other method works, isn't a good fit for what we're doing these days with putting more information into the errorinfo (such as help urls), and doesn't expose the batchResponse (for partial success) in a nice way. The batchResponse is currently exposed just by the fact that the whole response body (
{error: ErrorInfo, batchResponse: Array<...>}
) ends up as the first element of theitems
array, which is a pretty weird and unintuitive api.We'll likely be using this more and more as batch publishing goes into GA, token revocation uses it, etc. (All those will probably end up with first class support in all client libs eventually, but seems unlikely that'll be a high priority any time soon, so having a good rest#request seems important)
Couple sketches of possible alternative APIs:
rest#request signals errors the same way we do in every other api call (eg in js, the err argument of the callback, or rejected promise).
For the 'partial success' case, ErrorInfos will have an option
batchResponse
property (Array<JsonObject>
), which is populated with thebatchResponse
array.rest#request signals errors the same way we do in every other api call (eg in js, the err argument of the callback, or rejected promise).
For the 'partial success' case, we change the realtime implementation (triggered by a version flag of some kind) to just return the batchresponse array as the top level response, which would then always be
Array<JSONObject>
, e.g.Array<{channel: string, messageId?: string, error?: ErrorInfo}>
for batch publish. So we deprecate the "Batched response includes errors" errorinfo.The http request as a whole nominally suceeds (ie http status code is 201), and if someone wants to see if every individual item succeeded, they can check
batchResponses.every(br => !br.error)
, or the specific language equivalent.TBD: how we deal with the breaking change that this would introduce, given that it seems unlikely we're going to be releasing a 2.0 spec any time soon.
Opinions on those two, further suggestions of better request APIs, or arguments for keeping the original version all appreciated.
@QuintinWillison @AndyNicks @paddybyers @mattheworiordan @ben-pickering @lmars
┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: