Skip to content
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

Added method to expose DataResponse - RxAlamofire.request(...).responseJSON(). #79

Merged
merged 1 commit into from May 25, 2017

Conversation

freak4pc
Copy link
Member

@freak4pc freak4pc commented May 4, 2017

This PR aims to resolve issue #76

This PR allows using the following syntax to access the underlying DataResponse object of a request:

RxAlamofire
    .request(.get, "https://jsonplaceholder.typicode.com/posts/1") // Returns Observable<DataRequest>
    .responseJSON() // Returns Observable<DataResponse<Any>>
    .subscribe(onNext: { response in
        print(String(describing: response.result.value))
        print(response.timeline)
    })
    .addDisposableTo(disposeBag)

@freak4pc freak4pc changed the title Added method to access DataResponse RxAlamofire.request(...).responseJSON(). Added method to expose DataResponse - RxAlamofire.request(...).responseJSON(). May 4, 2017
@freak4pc freak4pc requested review from kzaher and sergdort May 4, 2017 22:09
@freak4pc freak4pc force-pushed the feature/dataresponse-access branch from ca582df to cb42ae0 Compare May 5, 2017 08:32
let request = self.base

request.responseJSON { response in
if let error = response.result.error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should send onError in this case as it's part of the response?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also contemplated with that. But if we skip the error part and let the request push the error, you would end up with both an error and a next event (next sent first along with an error). I had it set up this way but wasn't sure if it makes sense, I'm down changing back if it makes more sense but I'm worried on the underlying possible confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's our final opinion on this one? We ca go either way @sergdort

}
}

return Disposables.create {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure of it's nicer but you can also do

return Disposables.create(request.cancel)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm yeah sure I'll add that! I usually prefer doing the closure for readability but for a one liner that's nicer for sure. Thanks !

Copy link
Member Author

@freak4pc freak4pc May 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this would have to be
Disposables.create(with: request.cancel)

Which really isn't as neat. I think I'll leave this with a regular closure as its a bit easier on the eye. @sergdort

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@freak4pc
Copy link
Member Author

Could anyone help with pushing this through or giving a review? It's been sitting here for 20+ days.

@RxSwiftCommunity/contributors

@ashfurrow
Copy link
Member

Thanks for the poke, the PR makes sense to me but I admit I haven't used the library extensively, so another set of eyes couldn't hurt. If in doubt, merge and we can figure out the problems later 👍 Thanks again!

Copy link

@RafaelPlantard RafaelPlantard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

}
}

return Disposables.create {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@freak4pc freak4pc merged commit a781f9d into master May 25, 2017
@rynecheow rynecheow deleted the feature/dataresponse-access branch May 23, 2020 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants