I'm only familiar with native mobile development, not web development, so forgive my naïvety.
An API for a mobile app would usually involves requesting via POST or GET data from an API. The data would be returned as JSON. For the sake of this example, imagine the API is a simple one powered by Sinatra / Ruby, which would be consumed by both the mobile and website.
What are the options for website development using the same paradigm - with the web front-end getting it's data from the same JSON endpoints as the mobile app?
I've heard the names AngularJS and Backbone.js thrown around, though perhaps Sinatra is enough? I would prefer not to use PHP.
I would prefer a lightweight solution. If possible, I would like it to be able to update pages when the model changes, though I'm guessing this would depend on backend API changes.
You will get the biggest bang for your buck if your service and UI tiers are completely separate. And by that I mean, design your services without a particular UI in mind, because doing so gives you the maximum reuse for them. I would recommend a RESTful, web based service implementation because they give a great amount of flexibility for UI integration. There are literally legions of libraries now that are capable of consuming data from such services.
I am not a Ruby developer, but here is a simplistic web service implementation in Sinatra:
require 'rubygems'
require 'sinatra'
require 'lib/posts'
post '/posts'
post = Post.create! params
redirect "/posts/#{post.id}"
do
get 'posts/:id' do
@post = Post.find(params[:id])
erb :post
end
Attribution: Lightweight Webservices with Sinatra and RESTClient.
Note that the actual language/platform used for the service implementation is irrelevant, as long as its RESTful, and returns data that clients can easily consume. Once you have that setup, then designing a web app vs a mobile app becomes a matter of choosing an appropriate integration library:
As a real world example, my current project has a large number of RESTFul web-services built out using Java EE/JAX-RS running on clustered JBoss servers. The services return JSON by default, but can also generate XML, and are accessed from:
The exact same services are used by multiple different platforms/UI's, with no changes required on the service side. Which is what I believe you are trying to accomplish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With