Package ej.restserver
Class RestEndpoint
- java.lang.Object
-
- ej.restserver.RestEndpoint
-
- Direct Known Subclasses:
AliasEndpoint,ResourceRestEndpoint
public class RestEndpoint extends Object
A REST endpoint exposes resources on a REST server.Allow HTTP verbs are
GET,POST,PUTandDELETE.
-
-
Constructor Summary
Constructors Constructor Description RestEndpoint(String uri)Create a new endpoint at given URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HTTPResponsedelete(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesDELETErequest on this endpoint.HTTPResponseget(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesGETrequest on this endpoint.StringgetURI()Gets this endpoint URI.HTTPResponsepost(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesPOSTrequest on this endpoint.HTTPResponseput(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesPUTrequest on this endpoint.
-
-
-
Field Detail
-
uri
protected String uri
The URI this endpoint answers.
-
-
Constructor Detail
-
RestEndpoint
public RestEndpoint(String uri) throws IllegalArgumentException
Create a new endpoint at given URI.For example, assuming a REST server running at
127.0.0.1:80, following code creates an endpoint athttp://127.0.0.1:80/my/custom/endpointserver.add(new RestEndpoint("/my/custom/endpoint"));If URI does not start with a/character, it is automatically added.- Parameters:
uri- the URI of this endpoint.- Throws:
IllegalArgumentException- if URI is empty
-
-
Method Detail
-
getURI
public String getURI()
Gets this endpoint URI.- Returns:
- this endpoint URI.
-
get
public HTTPResponse get(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesGETrequest on this endpoint.Default implementation return a a status code
501- Parameters:
request- the request to handle.headers- request headers.parameters- parsed query and body parameters.- Returns:
- an HTTP response.
-
post
public HTTPResponse post(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesPOSTrequest on this endpoint.Default implementation return a a status code
501- Parameters:
request- the request to handle.headers- request headers.parameters- parsed query and body parameters.- Returns:
- an HTTP response.
-
put
public HTTPResponse put(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesPUTrequest on this endpoint.Default implementation return a a status code
501- Parameters:
request- the request to handle.headers- request headers.parameters- parsed query and body parameters.- Returns:
- an HTTP response.
-
delete
public HTTPResponse delete(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesDELETErequest on this endpoint.Default implementation return a a status code
501- Parameters:
request- the request to handle.headers- request headers.parameters- parsed query and body parameters.- Returns:
- an HTTP response.
-
-