public class RestEndpoint
extends java.lang.Object
Allow HTTP verbs are GET, POST, PUT and DELETE.
RestRequestHandler| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
uri
The URI this endpoint answers.
|
| Constructor and Description |
|---|
RestEndpoint(java.lang.String uri)
Creates a new endpoint at given URI.
|
| Modifier and Type | Method and Description |
|---|---|
HTTPResponse |
delete(HTTPRequest request,
java.util.Map<java.lang.String,java.lang.String> attributes)
Handles
DELETE request on this endpoint. |
HTTPResponse |
get(HTTPRequest request,
java.util.Map<java.lang.String,java.lang.String> attributes)
Handles
GET request on this endpoint. |
java.lang.String |
getURI()
Gets this endpoint URI.
|
boolean |
isGlobal()
Returns whether or not this endpoint is global, which means it can process sub-endpoints.
|
HTTPResponse |
post(HTTPRequest request,
java.util.Map<java.lang.String,java.lang.String> attributes)
Handles
POST request on this endpoint. |
HTTPResponse |
put(HTTPRequest request,
java.util.Map<java.lang.String,java.lang.String> attributes)
Handles
PUT request on this endpoint. |
public RestEndpoint(java.lang.String uri)
For example, assuming a server running at 127.0.0.1:80 with a REST request handler, following code
creates an endpoint at http://127.0.0.1:80/my/custom/endpoint
restRequestHandler.addEndpoint(new RestEndpoint("/my/custom/endpoint"));
If URI does not start with a / character, it is automatically added.
If URI ends with /*, the RestEndpoint created is a global endpoint and is able to process
requests to sub-endpoints.
For example, an endpoint created with the "/my/custom/*" URI is able to process, among others, the requests to "/my/custom" and "/my/custom/endpoint".
uri - the URI of this endpoint.java.lang.IllegalArgumentException - if URI is emptypublic java.lang.String getURI()
If this endpoint is global, the returned URI doesn't contain the trailing /* of the URI given to the
constructor.
public boolean isGlobal()
For example, a global /my/custom/* endpoint can process request to /my/custom/endpoint.
true if this endpoint is global, false otherwise.RestEndpoint(String)public HTTPResponse get(HTTPRequest request, java.util.Map<java.lang.String,java.lang.String> attributes)
GET request on this endpoint.
Default implementation return a status code 501
request - the request to handle.attributes - the attributes populated by the request processing.public HTTPResponse post(HTTPRequest request, java.util.Map<java.lang.String,java.lang.String> attributes)
POST request on this endpoint.
Default implementation return a status code 501
request - the request to handle.attributes - the attributes populated by the request processing.public HTTPResponse put(HTTPRequest request, java.util.Map<java.lang.String,java.lang.String> attributes)
PUT request on this endpoint.
Default implementation return a status code 501
request - the request to handle.attributes - the attributes populated by the request processing.public HTTPResponse delete(HTTPRequest request, java.util.Map<java.lang.String,java.lang.String> attributes)
DELETE request on this endpoint.
Default implementation return a status code 501
request - the request to handle.attributes - the attributes populated by the request processing.