views:

978

answers:

4

I am building a REST based API (Read only) for accessing services of my application. I plan on writing a web application that will leverage these APIs to provide basic information on the status of the application. I plan to use AJAX (using jQuery) to show the information.

Originally I planned on using Grails, Spring MVC, RoR or one of the web frameworks to handle the back end of my application. The REST APIs I will be providing though are already built on a stanalone REST framework so I would only be leveraging the web framework for the core application and not the business logic. In the future, I might need the server side framework to handle other tasks but for now most of the work is done in the REST APIs.

My question is, should I bother with using a web application framework on the server side? I should be able to make all the API calls I need from AJAX directly from the browser. I cannot think of much I would need to do on the server side. Would it make sense to have the application be standard HTML + AJAX + REST?

+1  A: 

Its hard to say without actually knowing more about your current setup. This is what your situation sounds like:

  • You already have an app ready to go with all of the business logic contained. Sounds like its written in Java?
  • You already have the services written and exposed through a REST api using some other standalone framework. Meaning that if you wanted to, you could access the data right now with the browser without any extra work.
  • You have not yet built the web application, but when you do, it will get all of its content from the REST api using XHR and jquery. I say that, because otherwise, I would think that you would already be using some kind of framework to generate the other content.

If I am correct in my assumptions, then I would say that you have no need for an additional framework layer. Grails, RoR, SpringMVC my use ajax, and aid in exposing REST services, but the bulk of what they provide is an easy way to make an application that must generate html on the server, deal with form submissions, and handle sessions in a request/response cycle. It doesn't really sound like you'll be doing any of that, and it will likely make your app more complicated.

If you did at some point need the things that rails etc. provides, I would say that you may not need to use rails to expose the rest apis you have now. You could use rails just for what you need, and continue to use what you have for the REST api.

Russell Leggett
A: 

Well, the AJAX calls need to pull data from a server somewhere. If the goal is to avoid a complicated setup on the server side, CherryPy can keep the server side code VERY small.

I've written a simple exapmle below. The first class would be where you put the logic for your ReST API. The code below the class is all you need to get the server up and running.

Install Python 2.6, save the code below to restExample.py. Then in your command line run the python file by doing "python restExample.py". Point your browser to http://localhost:8080/blog/999 and see some JSON come back.

import cherrypy
import json

# Create the controller
class Blog_Controller(object):
    def get(self, entryID):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps({'title':'Entry Title from DB', 'entry_text': 'Text From DB'})
    def update(self, entryID, titleFromPOSTFormInput, textFromPOSTFormInput):
        # Update DB with passed in arguments.  entryID comes from URL,
        # other two entries come from POST
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps({'success':True})

# Setup URL routes
d = cherrypy.dispatch.RoutesDispatcher()
d.connect(name='blog_entry', route='blog/:entryID', action='get',
          controller=Blog_Controller(),
          conditions={'method': ['GET']})
d.connect(name='blog_entry', route='blog/update/:entryID', action='update',
          controller=Blog_Controller(),
          conditions={'method': ['POST']})
config = { '/' : { 'request.dispatch': d } }
cherrypy.tree.mount(root=None, config=config)

# Start the webserver
engine = cherrypy.engine
try:
    engine.start()
except:
    sys.exit(1)
else:
    engine.block()
Eric Palakovich Carr
A: 

It sounds like this might be a good use case for GWT with Restlet.

laz
A: 

Forgive me for tooting my own horn, but if you are doing AJAX REST stuff with jQuery, you should probably check out my JSON-REST plugin:

http://plugins.jquery.com/project/rest

If you are getting XML back, then this won't be as useful, but you may still be able to adapt some of the code to your needs.

Nathan Bubna