A talk given at London Mobile Form 2.0 on Automating SDK generation.
If you are writing your mobile apps using multiple languages then automating SDK generation using codegen can bridge the gap between the backend and your front end clients; helping you develop your mobile apps far more rapidly. Remote Procedures should not be any harder to call than local calls and your mobile front-end developers should not need to know manually write networking or serialisation code.
By integrating such codegen tools into your automated (CI) development process, the resistance to adding new APIs and features is essentially removed. Your front-end and back-end teams can add features far more rapidly than they could before.
2. Bloom.fm
• Mobile-first music streaming
app
• Android, iOS, others coming
• Lean development team of 14
• 4 mobile developers
• Native apps (Java, Objective-C)
• 1 year on > 1 million users in UK
2
3. How best to help front-end developers consume rapidly evolving backend
APIs resulting from rapidly evolving requirements
• Most mobile apps talk to backends via HTTP based APIs
(aka webservices)
• Service-oriented applications generally require new
backend APIs for new features
• The less painful you make it to add a new API the less
painful it will be to add a new feature and the faster and
more agile your project will be
• A “wrapper” or “internal SDK” for the backend API is
required for each mobile client platform
3
4. Web Service Code Example
Backend code
[WebInvoke(Method = "GET", UriTemplate = "SearchAlbums?Query={query}&Skip={skip}&Take={take}")]
PagedAlbumsResponse SearchTracks(string query, int skip, int take)
{
return new PagedTracksResponse() { .Count = …, .Tracks = … };
}
4
Objective-C client code
[[self->userSession searchService] searchTracks:@"Oasis", 0, 10, ^(PagedTracksResponse* response)
{
NSLog(@”Track count: %d”, response.count);
}];
Java client code
this.userSession.searchService.searchTracks("Oasis", 0, 10, new PagedTracksResponseHandler()
{
void handle(PagedTracksResponse response)
{
System.out.println(”Track count: %d”, response.getCount());
}
};
5. Strategies for creating client side wrappers from backend APIs
1. Developers manually write wrappers (SDKs) for backend code
1. Bug prone copy/paste networking and serialization code
2. Slow turn-around time creates resistance to adding new APIs
2. Reduce the need to maintain an SDK for each language by writing mobile
apps in a single language
1. Phonegap
2. Xamarin/Mono
3. Flex
3. Codegen tools
1. Swagger for REST-like APIs
2. WSDL -> Language generators for SOAP services …eww SOAP
3. Bespoke tools
5
Copyright (c) 2014 Thong Nguyen
6. Bloom.fm solution
• In-house codegen tool: dto4lang (2 weeks to write)
• Founding principle: Making an RPC call to backend should be as
easy as making an in-process method call
• HTTP(S) + JSON over the wire
• Output languages: C++, Objective-C, Java, JavaScript
• Generates:
– All networking code
– All APIs as simple method calls
– Classes for complex types (DTOs)
– All serialization and deserialization code
6
7. Bloom.fm solution (cont)
• Code is generated directly from backend web service
definitions (directly from the C# service interface classes)
• Entire process is integrated into Mercurial and CI (TeamCity)
• In-team practice is to commit skeleton backend code with
dummy response data enabling client side development to
begin before backend code has been completed
• Turn-around time between commit of backend code and
client side SDK generation appearing in repo is < 3 minutes
• Compiler time warnings of obsolete, missing features or
incompatible changes.
7
9. Questions to explore
• Why has the industry not sufficiently settled on a standard
for API communication so that tools can be standardized
(thesis: CORBA, DCOM, SOAP scared everyone off)
• Are your teams manually writing wire protocols,
networking calls, serialization code? If not, what solutions
do you use?
• RPC style internal APIs are simpler for mobile apps. Are
RESTful style APIs helpful?
• How else can codegen help mobile development? e.g.
Converting SVG direct to native drawing APIs?
• Codegen is useful in multi-platform multi-language
situations but when should it be avoided?
9