Jetty 12 Programmer Documentation has this:
class RESTHandler extends Handler.Abstract
{
@Override
public boolean handle(Request request, Response response, Callback callback)
{
// Implement the REST APIs, remembering to complete the callback.
return true;
}
}
I would like to know how to create a REST API in the above block.
I know using Jersey and Servlet Container it is possible to create. But not sure how to create REST API using Jetty Handlers alone.
The one option that is possible is to parse the request using request.getComponents() and tokenizing request params.
I was trying to use:
request.getComponents()
which would return like this:
HttpChannelState@d735a98{handling=Thread[server-20,5,main], handled=false, send=SENDING, completed=false, request=GET@0 http://localhost:8080/shop/?id=122&city=new%20york&country=usa HTTP/1.1}
Need help please.
Thanks in advance.
The one option that is possible is to parse the request using request.getComponents() and tokenizing request params.
The request.getComponents()
is for Components that are shared across all handlers and requests on the same connection. There is rarely a need to access or use this object, and it exists for integration into cloud providers.
The raw query is available in the HttpURI
on the request.
String rawQuery = request.getHttpURI().getQuery();
But then you would have to parse and url-decode that string yourself.
A convenience method is provided to do that for you.
Fields query = Request.extractQueryParameters(request,
StandardCharsets.UTF_8);
String member = query.getValue("Member");
This snippet is from the form-post
examples found at
See the documentation for other examples on how to read from the request, and write to the response.