Some content

@Web[REST] Annotations (since 2.0.0)


A @Web[REST] Methods is a methods annotated with @WebGet, @WebPost, @WebPut, @WebDelete. Snow will bind the matching HTTP request to this annotated method as

public [ReturnName] methodName(/* ... dynamic parameters (see WebParams) ... */){
  • path is optional. If not present, the path will be the "/[methodName]".

    So, a HTTP-GET on the URI "/getSomething" would match to

    public Object getSomething(/* ... dynamic parameters (see WebParams) ... */){
  • path can have {varName} to define some @PathVar.

    So, the URI "/delete-item-123" would match to

    public Object aRestGet(@PathVar("id")Long id){
      // id == 123
  • The method parameters is dynamic, see WebParam for more information. In short, you can use @WebParam and @PathVar and even define your custom param resolvers, and none of those match, Snow will attempt to resolve the parameter with Google Guice (allowing you to inject Guice bound object as well)
  • ReturnType is optional as well and can be void.

    So, a HTTP-POST on "/create-item" will return an empty body.

    public void createAnItem(@WebParam("title")String title)...
  • The return ResultType instance will be serialized to JSON with the default JsonRenderer.

    So, a HTTP-GET on "/item?id=123" will get the JSON for the item.

    public Item getAnItem(@WebParam("id")Long itemId){
      return itemManager.getItem(itemId);

    Would return a json like.

    {id: 123,
     title: "A very interesting title"}
  • If ReturnType is of type String, then, it is assumed that the String is the JSON.

    So, a HTTP-GET on "/items-count".

    public String getItemsCount(){
      return "{\"count\":1001}";