-
Notifications
You must be signed in to change notification settings - Fork 12
REST Mapper: Service API
This page refers to las2peer versions older than 0.6.1!
las2peer uses JAX-RS, Swagger and some custom annotations defined in the REST Mapper submodule to handle REST calls and generate API documentations.
The following JAX-RS annotations are supported:
- Class Annotations
- @Consumes
- @Path
- @Produces
- Method Annotations
- @Consumes
- @DELETE
- @GET
- @Path
- @POST
- @Produces
- @PUT
- Parameter Annotations
- @ContentParam
- @DefaultValue
- @HeaderParam
- @HttpHeaders
- @PathParam
- @QueryParam
Furthermore, all Swagger annotations are supported, since Swagger itself is used for API listing generation.
Additionally, the following annotations are introduced by the REST Mapper:
Specifies the parameter to contain the body of a POST request.
The content of the body is processed inside the method (no pre-processing).
You can use @Consumes
to specify which MIME-types the method accepts.
@POST
@Consumes({"text/plain"})
public String method1(@ContentParam String content)
{
return content;
}
Maps all http-header fields and their values to a parameter in the format:
field1: value1
field2: value2
field3: value3
...
The type T of the annotated parameter must be java.lang.String, e.g.: public String method1(@HttpHeaders String headers)
HttpResponse is a return Type, which can be used to manipulate response headers, set a response code and a response value (return value).
The constructor expects the response value as a string and optionally the response code. If no response code is provided, 200 is used as a default. Header values can be set using setHeader(field,value)
. To specify the Content-Type
you should use the @Produces
annotation.
@GET
public HttpResponse method1()
{
HttpResponse response=new HttpResponse("",200);
response.setHeader("myheader1","myHeaderValue1");
response.setHeader("myheader1","myHeaderValue2");
return response;
}
Currently REST Mapper supports only simple types as parameter and return types:
- int
- byte
- short
- long
- float
- double
- char
- boolean
- String
- Integer
- Byte
- Short
- Long
- Float
- Double
- Boolean
- Character
Additionally HttpResponse
is supported as a special return type that allows to manipulate response headers and response codes.