public class RestEndpoint extends Object
Allow HTTP verbs are GET
, POST
, PUT
and DELETE
.
Modifier and Type | Field and Description |
---|---|
protected String |
uri
The URI this endpoint answers.
|
Constructor and Description |
---|
RestEndpoint(String uri)
Create a new endpoint at given URI.
|
Modifier and Type | Method and Description |
---|---|
HTTPResponse |
delete(HTTPRequest request,
Map<String,String> headers,
Map<String,String> parameters)
Handles
DELETE request on this endpoint. |
HTTPResponse |
get(HTTPRequest request,
Map<String,String> headers,
Map<String,String> parameters)
Handles
GET request on this endpoint. |
String |
getURI()
Gets this endpoint URI.
|
HTTPResponse |
post(HTTPRequest request,
Map<String,String> headers,
Map<String,String> parameters)
Handles
POST request on this endpoint. |
HTTPResponse |
put(HTTPRequest request,
Map<String,String> headers,
Map<String,String> parameters)
Handles
PUT request on this endpoint. |
protected String uri
public RestEndpoint(String uri) throws IllegalArgumentException
For example, assuming a REST server running at 127.0.0.1:80
, following code creates an endpoint at
http://127.0.0.1:80/my/custom/endpoint
server.add(new RestEndpoint("/my/custom/endpoint"));If URI does not start with a
/
character, it is automatically added.uri
- the URI of this endpoint.IllegalArgumentException
- if URI is emptypublic HTTPResponse delete(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)
DELETE
request on this endpoint.
Default implementation return a a status code 501
request
- the request to handle.headers
- request headers.parameters
- parsed query and body parameters.public HTTPResponse get(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)
GET
request on this endpoint.
Default implementation return a a status code 501
request
- the request to handle.headers
- request headers.parameters
- parsed query and body parameters.public String getURI()
public HTTPResponse post(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)
POST
request on this endpoint.
Default implementation return a a status code 501
request
- the request to handle.headers
- request headers.parameters
- parsed query and body parameters.public HTTPResponse put(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)
PUT
request on this endpoint.
Default implementation return a a status code 501
request
- the request to handle.headers
- request headers.parameters
- parsed query and body parameters.