REST vs Native API for cross-platform app

#1

I am building a cross-platform app in C++ and want to use Couchbase Lite to store and manage data. Initially I was planning to use the Native API and rewrite it for each platform (I want to support as many platforms as possibly). However, now I’ve noticed the REST API I think that would be a better option. I can use a cURL library to make the calls, and use the same code across all platforms :+1:

Are there any disadvantages to the REST API vs the Native API? Especially with regards to replication?

#2

The REST API is not a standalone product, it depends on the Couchbase Lite library for its logic. It simply exposes an instance of Couchbase Lite to the outside world. Currently the most cross platform solutions we have are .NET, which will target anything with a .NET 3.5 compatible runtime or higher (iOS, Android, Windows, OS X, Linux, Unity3D) and Java, which runs on any J2SE platform.

#3

Thanks, I realise the REST API is a part of Couchbase Lite. What I am trying to achieve is the minimum amount of bridge code for each platform, and ideally without the need to ship an extra runtime with the app. So I’m wondering if I can use e.g. the Objective-C version for iOS/OSX, Java on Android, .NET on Windows; start the Couchbase Lite server on app start up and then make REST requests to localhost via cURL or similar using the same C++ code for all platforms.

#4

Sure, you can do that. The REST API has a bit more overhead than the native one because requests have to be marshaled into JSON and HTTP, but it’s not excessive.

Of course you’re going to have to use another cross platform layer for your UI too, and you’ll also need to customize the UI for each platform so it will use the right idioms and not feel like a port. IMHO this is more trouble than it’s worth – I’d rather use the native UI toolkit on each platform – but that’s off topic for this forum, and anyway it’s your app and you make the decisions (:

#5

Thanks for the info on that - I am already using the JUCE C++ library for everything else in my app (audio and UI) and I’m fine with a single custom UI across platforms (maybe just a few different icons to match the OS style).