0

I have been providing a Web API (.NET MVC 5) of an Oracle Database to people who are making a mobile app. I have to admit that I am not very good at it. I have found that I can easily produce Data Transfer Objects to make very simple JSON displays.

My question is whether it is feasible to ask the mobile developers to make multiple calls to the API to get the data they need. This would be in opposition to me providing a more complex model that provides all the info in ONE call.

As a pure example... if we were dealing with animals, in my API they would need to call both the category (api/categories) and the animal name (api/animals) and link the 2 together depending on their needs:

.....call 1 to category_table

[{
CATEGORY_ID: 1,
CATEGORY_NAME: "Dog"
},
{
CATEGORY_ID: 2,
CATEGORY_NAME: "Cat"
}]

.....call 2 to animal_table

[{
ANIMAL_ID: 1,
CATEGORY_ID: 2,
NAME: Tabby
},
{
ANIMAL_ID: 2,
CATEGORY_ID: 2,
NAME: Lion
},
{
...etc,etc,
}
]

The other option would be to use more complex JSON utilizing arrays so that they only make one call. That I am having some difficulty with. At the moment the APIs are very simple so they may have to call a few APIs. I tried directly using the model that I had created from the DB but ended up with humongous amounts of data being produced (arrays inside arrays inside arrays... etc, etc,). I had to use DTOs but I am having difficulty using arrays.

The question is whether it is feasible to have those developers make multiple calls instead of a more complex JSON response. They will be programming for IOS mobile devices using swift.

In other words I could place an array of each animal into the categories call (it was maybe a simplistic example). I am not talking about putting the category_name in the api/animals... that would be easy! I mean some form of associative arrays.

  • The question is not clear to me. But maybe this makes sense. The apps can fetch category data once and cache it. It seems you have master data on the one hand that never changes and dynamic data on the other hand that may require multiple, periodic calls. Fetching the master data once upfront does not seem to be a big issue if it means you can keep your API primitive like it should be. – Martin Maat Mar 5 '16 at 19:13
  • Have a look at OData. This has a good command and query set on top of REST, a standard way of doing joins, transactions, etc. – Erik Eidt Mar 5 '16 at 19:43
  • But the best I can do is get a basic list of values so: [{names:values},{names:values},{names:values}]. That is it! No arrays inside those list items. Just a completely basic list of basic name value pairs in that format. It means that in order to do anything they have to call several tables (api/table) and then extract what they need. – Cheesus Toast Mar 5 '16 at 20:40
1

It's a matter of satisfying DRY as much as possible. You say your service only has one client, an iOS app, but what happens when someone decides that an Android app or web app should be written? How much of the logic is that second app going to have to duplicate because of how you wrote the service?

Write your service in such a way as to reduce duplicated logic as much as possible. That means that if your API requires all clients to call categories before they can call animals, then you are forcing all clients to duplicate logic.

Yes, this means more work for you, the beleaguered service provider, but it's better to have one programmer in charge of one piece of logic built in one place than have multiple programmers each in charge of handling that one piece of logic in several different places.

  • It was mostly to do with the one dimensional data that I was producing. I have actually found a way to make it more complex now so they are getting more details out with one call. I agree with what you are saying though. I do want to produce the most effective responses for all those concerned. – Cheesus Toast Mar 8 '16 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.