Well, I was wondering how I could do this or how this is done.
Having a server that accepts HTTP Requests and maintains a database for a mobile app, it is supposed to provide data for Android and iOS – or let’s say – for more than one client.
Now that I write the Android client in Java and the iOS client in Objective-C I cannot simply have a shared project between my clients and the server for them to know how the objects returned from the server as JSON are supposed to look like as runtime objects.
For example if my server returns a simple Java object that gets marshalled to JSON:
public class Person {
public String name;
public int age;
}
// ..
public Person[] getListOfPersons(int minAge, int maxAge) {
// ..
return personList[];
}
How can I introduce this return value for all kind of clients without having to write every object over and over again?
3
You might want to use Google Protocol Buffers.
You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python.
There are any number of solutions to this, but fundamentally what you’re looking for is some way to provide a specification file for your API that can be used to create a client for that API.
If you create a “level 3” REST API (see: Richardson Maturity Model) then you can almost leave it to the client to figure out (although in fact implementations seem to rely on the API providing some structured data according to a standard to “help” the client). However there’s a chunk about getting to that level that is hard – at both ends.
So more pragmatically you pick a api/schema definition and one that appears to be gaining significant traction is Swagger and on github.