REST Principles

December 13, 2012

REST stands for Representational State Transfer

5 key principles of REST are –

  • Give everything a ID


  • Link things together

Links help to refer to identifiable things

  • Use standard methods

GET- To retrieve a representation. Its idempotent, meaning that has no additional effect if it is called more than once with the same input parameters
PUT – update this resource with this data, or create it at this URI if it’s not there already. Its idempotent.
DELETE – delete a resource. Its idempotent.
POST – create a new resource. Its not idempotent.

  • Resources with multiple representations

Provide multiple representations of resources for different needs.

  • Communicate statelessly

A server should not have to retain some sort of communication state for any of the clients it communicates with beyond a single request. The most obvious reason for this is scalability — the number of clients interacting would seriously impact the server’s footprint if it had to keep client state.


XMLHTTP AJAX abort(), jQuery abort()

March 10, 2011

I was looking if there was a way to stop an already running AJAX request, like we can stop an http request using browser stop button. Yes there is a way to stop it using abort() method of the XMLHttpRequest object . More details about this here

jQuery JSONP (JSON with padding) – success method not called

February 23, 2011

Possible reasons for JSONP success method not getting called

  • In jQuery.getJSON method check if you are adding the
    callback=? param to your URL
  • Check if your server code serving JSONP request is returning proper JSONP response,

    For example sample server JSONP java code and response taken from IBM Developerworks article given below,
    Java code

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    String jsonData = getDataAsJson(req.getParameter("symbol"));
    String output = req.getParameter("callback") + "(" + jsonData + ");";


    PrintWriter out = resp.getWriter();

    JSONP Response Format

    jsonp1232617941775({"symbol" : "IBM", "price" : "91.42"});

To get a good understanding of JSONP you can read this IBM Developerworks article

what http error code to use for validation error

February 18, 2011

I was using 500 – Internal Server Error for validation errors, but problem was the application error handler caught this and shows generic error page, which causes validation logic to fail. So instead we can use

Either use code 400 – Bad Request
or code 200 – with the error message

Handling cookies with java URLConnection

January 17, 2011

Same way you can set other headers like Content-Type, Accept to the HTTP request using the setRequestProperty method of URLConnection

Firefox addon to build HTTP request

January 17, 2011

This needs comes up when you cannot test build HTTP GET or POST request requiring special request headers like content type = application/json;

Apache mod_rewrite NE|noescape

August 27, 2010

I faced an issue where the URL for example /saved/ was getting rewritten to %2Fsaved%2F, which caused the web application to give 404 error because it expects the URL without escaped/encoded characters.

I found this Stack Overflow thread related to this problem which gave the solution,

Add NE flag to prevent escaping –