Git Product home page Git Product logo

play-jaxrs's Introduction

play-jaxrs is providing an alternative router for play 2.1.2 (and above) java apps by implementing (a subset of) the JAX-RS specification on top of play.

tl;dr

use this router instead of the built-in one if you are interested in a native java solution that also significantly improves build times. The price you will need to pay for this is lack of reverse routing and compile time routing checks.

play-jaxrs tradeoffs

  • using reflection for action dispatching instead of matching generated route rules

  • since there are no router files to compile and sbt can not invalidate big parts of the object graph, compile times are significantly better than using the standard solution

  • only supports java projects for two reasons:

    • annotations are primary used in java
    • scala users already have a very scala-centric routing solution
  • route definitions are provided inline. Some people prefer this over an external DSL, especially in a backend service-only context

  • reflection based dispatching means no reverse routing or compile time checks for route matching

  • since there is no route file, assets controller is configured via the config file

what's supported?

  • @GET,@POST, @PUT, @DELETE, @OPTIONS

  • @ApplicationPath on your Global class can define a context (think servlet context)

  • @Path works both on classes and methods

  • URI parts can be captured (i.e. /user/id/{id})

  • the captured field can only be a String i.e.

    @GET
    @Path("/id/{id}")
    public static Result id(@PathParam("id") String id) {
        ...        
    }
  • @QueryParam captured as com.google.common.base.Optional i.e.
@GET
@Path("/id/{id}")
public static Result id(@PathParam("id") String id, @QueryParam("foo") Optional<String> foo) {
    return ok("id=" + id + " query=" + foo.or("booo"));
}
  • @Provides
  • @Consumes

plus all the standard play features should be working (i.e. action composition, dependency injection, assets serving etc.).

Curious?

How to install

you can install play-jaxrs in three easy steps:

  1. delete conf/routes

  2. in project/Build.scala add

"org.pk11" %% "jax-rs" % "0.6"

to your project/Build.scala file's app dependencies section.

  1. also

resolvers += "pk11" at "http://pk11-scratch.googlecode.com/svn/trunk"

should be part of your settings

  1. edit conf/play.plugins 1500:org.pk11.jaxrs.RouterPlugin

  2. finally, set it up in your Global class:

  @Override 
   public play.api.mvc.Handler onRouteRequest(RequestHeader request) {
     return Play.application().plugin(org.pk11.jaxrs.RouterPlugin.class).handlerFor(this, request);
  }

and that's it.

How to hack

after cloning and cd-ing into the main directory

run the spec

$ play test

package

$ play -Djaxrs=only publish-local

License

Published under The MIT License, see LICENSE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.