Skip to content

flextao/jrest-route

Repository files navigation

jrest-route

Support jrest-route version: 1.x.x

jrest-route aims to build a very simple and small REST route framework.

What it solves

  • Route a REST request to a resource controller. For example, in case we define a resource users:

    Routes routes = new Routes();
    // UserResourceController is a subclass of com.flextao.rest.ResourceController.
    routes.getResourceMap().add("users", UserResourceController.class);
    Then, delegate:
       HttpServlet#doGet         => Routes#doGet
       HttpServlet#doPost        => Routes#doPost
       HttpServlet#doDelete      => Routes#doDelete
       HttpServlet#doPut         => Routes#doPut
    (see com.flextao.rest.http.RestServlet how it works)
    Then you get:
      GET    http://domain:port/contextPath/users    maps to the UserResourceController#list action
        => response user list resource as response body (json format content as default)
      GET    http://domain:port/contextPath/users/id maps to the UserResourceController#show action
        => response the user resource found by id as response body
      POST   http://domain:port/contextPath/users    maps to the UserResourceController#create action
        => post with the user resource as request body (json format content as default)
        => response a header named 'Location' with created resource uri
      PUT    http://domain:port/contextPath/users/id maps to the UserResourceController#update action
        => post with the user resource as request body (json format content as default)
        => response the user resource updated as response body
      DELETE http://domain:port/contextPath/users/id maps to the UserResourceController#delete action
        => response nothing
    jrest-route provides a simple RestServlet, using servlet init-params to define resource, see com.flextao.rest.http.RestServlet for details.
    jrest-route also provides a simple abstract Basic Authentication filter implementation, see: com.flextao.rest.http.AbstractBasicAuthFilter for details.
  • Currently supports json & xml format.

    By default, jrest-route processes request content as json and response as json format. You could specify request content format type by request content type:

    application/json => json format
    application/xml  => xml format

    You also could specify response content format by uri ending with .json or .xml

Dependencies

runtime jars:

gson-1.3.jar for json format
servlet-api-2.5-6.1.1.jar 
inflector.jar

License

jrest-route is available under an MIT License Copyright © 2009 Flextao.

Author

Li Xiao <xli@flextao.com>

About

A simple &amp; small Java REST route framework for building a RESTful web application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages