-
Notifications
You must be signed in to change notification settings - Fork 29
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
Separate "Request" and "Task" APIs? #45
Comments
👍 👍 I am very much in favor splitting up This is how I've envisioned the changes:
With the
Building a request off of
The chaining methods could be moved to
Of course this means that syntax like this will no longer be possible but this should be considered an improvement for the sake of clarity and safer code:
We could retain the chaining behavior from request-to-response if we added a method to
But reading this code is a little odd because It is worth noting that the original API for building requests was not well-received and there was a lot of Slack discussion to change it that ended with the consensus favoring the chaining style for request building. Also worth noting is that this setter chaining style is called out as something that should be avoided in the best practices guide that we forked into Electrode-iOS. Since this has been a debated subject in the past, I'd like to get some feedback from others before we make a decision on what the API should look like to separate |
Glad to hear you feel the same way. There's one thing that concerns me about this pattern: service
.serviceTask(request: request)
.response { data, response in /* snip */ }
.resume() Which is that there is no help from the compiler to make sure that you call Thinking about it, I'm not sure that |
tl;dr
Maybe the
ServiceTask
request-building methods should be separated from the response-processing methods.Discussion
The
ServiceTask
is used both for setting up a request, and for pausing/resuming/processing the response. In practice, it's not very common to want to expose both APIs. It can lead to confusing situations like this:The "special auth header" will not be sent to the server because a snapshot of the request was created when
resume()
was called. But the calling code has no good indication that the request can no longer be modified.Here's another one:
This service call is never sent and there's no obvious indication why.
Proposed Changes
As part of the breaking changes for version 4, I'd like to propose removing the request-building methods from
ServiceTask
. Since these methods all just call through to the underlyingRequest
instance, we could just expose the request directly instead. The API changes might look something like this:And here's a usage example:
And another:
Unanswered questions
I'm not sure how the passthrough delegate should be assigned in this scenario. One thought is that the
ServiceTask
could check whether itssession
is aWebService
, and actively pull the delegate from it.I don't love the
session
parameter tosend()
, although it's also kind of cool how it allows you to save off a request and send it multiple times (if that's something you're in to).The text was updated successfully, but these errors were encountered: