3lvis / Networking

Swift HTTP Networking with stubbing and caching support
MIT License
1.36k stars 112 forks source link

Support for JSONDecoder #210

Closed aasatt closed 7 years ago

aasatt commented 7 years ago

With Swift 4 we have JSONDecoder to make Data to our objects. No need to go through array or dictionary body. To use Networking with this it seems we have to turn these results back into JSON data and then pass it into the decoder.

What do you think the best way to get the raw data from the result would be?

I was thinking just a .data parameter along with .arrayBody and .dictionaryBody on the ResultType.Success

Would you be open to something like this?

3lvis commented 7 years ago

Hi Aaron!

Adding .data to the ResultType.Success sounds like the best solution for this. 👌 Go for it!

aasatt commented 7 years ago

Can't decide on the best way to implement this.

Do you think it's acceptable to convert back to data on the fly when requested? Or do we need to go as far back as handleJSONRequest where the data is deserialized?

3lvis commented 7 years ago

Made a PR for this, need to add unit tests.

https://github.com/3lvis/Networking/pull/211

3lvis commented 7 years ago

Hi @aasatt, could you check master and see if it is what you needed?

Best :)

3lvis commented 7 years ago

Added a data accessor to the response that should return the same data returned by URLSession. https://github.com/3lvis/Networking/blob/2a2a41ca88a5d87f3d81b7bf90d1b9a86819985d/Tests/ResponseTests.swift#L7-L17

3lvis commented 7 years ago

I hope this helps. Let me know if I can help with anything else :)

aasatt commented 7 years ago

Didn't get a chance to look at it until now. Looks great! Thank you for this!

3lvis commented 7 years ago

Shipped in https://github.com/3lvis/Networking/releases/tag/4.1.0