freshOS / ws-deprecated

⚠️ Deprecated - (in favour of Networking) :cloud: Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
MIT License
353 stars 32 forks source link

Adds a default collection parsing keypath #29

Closed s4cha closed 7 years ago

s4cha commented 7 years ago

Use case

When most of the api calls returning a collection of objects use the same key path, then the code to write those requests is very redundant. For instance, in Yummypets near 50 requests are wrapped in a "collection" key path.

Thanks to a default collection parsing key, the code becomes more concise.

For readability's sake, the old jsonParsingColletionKey has been made unavailable and renamed to a more understandable defaultCollectionParsingKeyPath used like so :

ws.defaultCollectionParsingKeyPath = "collection"

Reasons

Writing this keypath evertime is very redundant.

This used to be supported and removing this useful feature would break client code, and this silently, which is very dangerous.

This would also require people to write more code, which is against what we're trying to achieve ))

Best of both worlds

Of course, the defaultCollectionParsingKeyPath is overriden if a keypath is passed per request.

This allows both default and per-request configuration, allowing best of both worlds.