nioto > Wink.JS

Wink.JS Api Client

Compiling Wink.JS

Generate your script

How to use Wink.JS

Run a demo example

Todo

Version history

A look of the javascript code

For each Rest resources, there is a corresponding Javascript method.

@Path("/")
public interface X{
 @GET
 public String Y();
 @PUT
 public void Z(String entity);
}

will generate 2 methods :

Winkjs.X.Y(params){...}
Winkjs.X.Z(params){...}

The params parameter

(from http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/AJAX_Client.html)

API parameter properties
Property name Default Description
$entity The entity to send as a PUT, POST request.
$contentType As determined by @Consumes. The MIME type of the body entity sent as the Content-Type header.
$accepts Determined by @Provides, defaults to */*. The accepted MIME types sent as the Accept header.
$callback Set to a function(httpCode, xmlHttpRequest, value) for an asynchronous call. If not present, the call will be synchronous and return the value.
$apiURL Determined by container Set to the base URI of your JAX-RS endpoint, not including the last slash.
$username If username and password are set, they will be used for credentials for the request.
$password If username and password are set, they will be used for credentials for the request.

Using the API

@Path("foo")
public class Foo{
 @Path("{id}")
 @GET
 public String get(@PathParam("id") int id, @QueryParam("order") String order, @HeaderParam("X-Foo") String header,
                   @MatrixParam("colour") String colour, @CookieParam("Foo-Cookie") String cookie){
  
 }
 @POST
 public void post(String text){
 }
}

We can use the previous JAX-RS API in JavaScript using the following code:

var text = Winkjs.Foo.get({id: 45, order: 'desc', 'X-Foo': 'hello', colour: 'blue', 'Foo-Cookie': 123987235444});
Winkjs.Foo.put({$entity: text});