I decided to use Mantle to consume some JSON endpoints, but the structure of the JSON is different depending on whether you're GET
ing or POST
ing an object. Take the users endpoint for instance:
When requesting a user you get a response similar to this:
{
"random_meta_data": "whatever",
"etc.": "etc.",
"payload": {
"username": "username",
"email": "[email protected]",
"etc.": "etc."
}
}
When creating a user you need to send something like this:
{
"username": "username",
"email": "[email protected]",
"etc.": "etc."
}
It's not a difficult problem to solve, but it seems like a common enough problem that Mantle
should be able to solve it for you.
I know I could simply initialize the mantle model with dictionary[@"payload"]
, but Overcoat
is doing the mapping for me automatically and if I'm going to do that manually I'm not taking advantage of Overcoat
anymore.
So I'm wondering if there is a standard way of solving this with Mantle
and/or Overcoat
?
What you are describing is called an envelop response and you can read about how to deal with those in the
Overcoat
README.md:https://github.com/Overcoat/Overcoat#envelop-and-error-responses