Code Monkey home page Code Monkey logo

gwt-jackson-rest's Introduction

gwt-jackson-rest

gwt-jackson-rest is a simple GWT REST client using gwt-jackson. It includes an api and an annotation processor which generates an helper class to easily send REST request to an annotated REST service.

Quick start

Add <inherits name="com.github.nmorel.gwtjackson.rest.GwtJacksonRest" /> to your module descriptor XML file.

Then annotate your REST service with the annotation GenRestBuilder. An helper class will be generated in the same package by default. You can specify your package by passing the option package to the annotation processor.

Check the example.

With Maven

<dependency>
  <groupId>com.github.nmorel.gwtjackson</groupId>
  <artifactId>gwt-jackson-rest-processor</artifactId>
  <version>0.5.1</version>
  <scope>provided</scope>
</dependency>

You can also get maven snapshots using the following repository :

<repository>
  <id>oss-sonatype-snapshots</id>
  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Copyright and license

Copyright 2015 Nicolas Morel under the Apache 2.0 license.

gwt-jackson-rest's People

Contributors

jufeel avatar nmorel avatar rsertelon avatar yissacharcw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gwt-jackson-rest's Issues

Support Jersey file upload

I am trying to use @GenRestBuilder on an API that uses Jersey multipart data for file upload. The annotation processor fails with the exception

Cannot have more than one body parameter

My method looks like the following:

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(@FormDataParam("file") InputStream stream,
                   @FormDataParam("file") FormDataContentDisposition fileDetail {
 // do something
}

The ideal would be if multipart data upload could be supported by the generator, but if that's not possible it would be nice if I could tell the annotation processor to ignore this method. I have many other methods in this file that I would like to generate but the exception stops the generation for those methods as well.

RestRequestBuilder adds Content-Type header when it should not

RestRequestBuilder automatically adds a Content-Type header with value application/json; charset=utf-8 whatever the method of the request.

This leads to browser potentially sending uneeded OPTIONS requests when CORS is used. (And, also, it shouldn't be sent).

Path params never initialized

I am trying to call an API with path params:

MyApiBuilder.getSomething()
  .addPathParam("foo", "bar")
  .send();

However this results in an NPE since in RestRequestBuilder the pathParams are never initialized.

Support for sub-resources?

There is not support for sub-resources. This is not a problem per se, but we use them quite extensively in our APIs, it would be nice to add support for them.

The way I see it is that it is "just" a recursion level to add. I'm on holiday this evening, but I might try to implement it when I get back to work.

Support for regex in Path Param

JAX-RS allows path params to contain regex (for URI matching).

Sadly, there do not seem to be any support for this in gwt jackson rest.

I might be able to try and create a pull request if it helps.

Handling @Context HttpServletRequest

Using the Context annotation is common in JAX-RS to retrieve the current HttpServletRequest. This allows for retrieving the current session, amongst other useful things.

Currently it seems that gwt-jackson-rest does not perform any exclusions for Context annotated params. Instead they are generated as part of the API, which causes the code to fail to compile since HttpServletRequest is not available in GWT.

What should happen instead is that a Context annotated HttpServletRequest param should be excluded from the generated code, since it is not passed in to the API manually, but rather handled automatically by JAX-RS on the server-side.

Null query/path params not handled

RestRequestBuilder doesn't check for null params and exclude them from being added to the URL. Currently a null param is an NPE.

I have a method that takes a lot of different query params, however only a few are usually used. Due to the design of the generated API method, I am forced to pass in every param. It would be great if I could pass in null for a param to indicate that I don't want that param added to the URL for this request.

Implement toString() on each Builder for debugging purposes

My Builder can't connect to my backend (probably due to some typo in my application path or so),
so I 'd like to print out the URL that is actually used.

When I do this in GWT, I don't get the url:

"URL " + EmployeeServiceBuilder.getEmployeeList().toString())

A toUrl() method or an override of toString() that says the url, would be nice.

addQueryParam with Collection

Hi,

I think

public RestRequestBuilder<B, R> addQueryParam( String name, Collection<Object> values);

should be changed to

public RestRequestBuilder<B, R> addQueryParam( String name, Collection<?> values);

because if your service looks like

public Map<Integer, MyBean> getForIDs(@QueryParam("id") List<Integer> idsList);

the generated code is :

public static final RestRequestBuilder<Void, Map<Integer, MyBean>> getForIDs(final List<Integer> idsList) {
    return new RestRequestBuilder<Void, Map<Integer, MyBean>>()
          .method(RequestBuilder.GET)
          .url("mypath")
          .addQueryParam("id", idsList)
          .responseConverter(getObjectReader1());
  }

but

addQueryParam( String name, Object value )

is called instead of

addQueryParam( String name, Collection<Object> values)

because Collection<Object> is not a supertype of all kinds of collections but Collection<?> should be.

Same problem with

addQueryParam( String name, Iterable<Object> values );

Thanks for your libraries.

Julien

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.