public interface RESTfulService
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getEndpointPath()
Returns the name of the Enpoint path used to invoke the RESTful web service.
|
java.lang.String |
getMethod()
Returns the HTTP Method e.g POST, GET etc..
|
java.lang.String |
getPathParameter(java.lang.String parameter)
Returns a path parameter based on the configured endpoint path parameter.
|
java.util.Map<java.lang.String,java.lang.Object> |
getPathParameters()
Returns all of the HTTP path parameters configured on the endpoint path as a JavaScript object
Further documentation.
|
java.lang.String |
getRequestBody()
Returns the request body.
|
java.lang.String |
getRequestContentType()
Returns the HTTP request content type
Further documentation.
|
java.lang.String |
getRequestHeader(java.lang.String header)
Returns a request header by a specific name.
|
java.util.Map<java.lang.String,java.lang.Object> |
getRequestHeaders()
Returns all of the HTTP request headers as a JavaScript object
Further documentation.
|
java.lang.String |
getRequestParameter(java.lang.String parameter)
Returns a parameter by a specific name.
|
java.util.Map<java.lang.String,java.lang.Object> |
getRequestParameters()
Returns all of the HTTP parameters as a JavaScript object
Further documentation.
|
com.ebasetech.xi.services.auth.UserCredentials |
readBasicAuthenticationCredentials()
Returns the
UserCredentials from the HTTP Basic Access Authentication. |
void |
removeResponseHeader(java.lang.String name)
Removes a response header by name
Further documentation.
|
void |
setResponseBody(java.lang.String responseBody)
Sets the response body
|
void |
setResponseContentType(java.lang.String contentType)
Sets the HTTP response content type
Further documentation.
|
void |
setResponseHeader(java.lang.String name,
java.lang.String value)
Sets a response header by name and value.
|
void |
setResponseStatus(int status)
Sets the response status e.g 200 for OK
|
java.lang.String getEndpointPath()
java.lang.String getMethod()
java.lang.String getPathParameter(java.lang.String parameter)
Javascript example:
var customerId = form.rest.getPathParameter("customerId"); //get customer details ...
java.lang.String getRequestParameter(java.lang.String parameter)
Javascript example:
// get the parameter from the endpoint. var username = form.rest.getParameter("username"); //get user details ...
java.lang.String getRequestHeader(java.lang.String header)
Javascript example:
//get the post parameter var username = form.rest.getRequestHeader("username"); //get user details ...
java.lang.String getRequestBody()
Javascript example:
//get the post parameter var body = form.rest.getRequestBody(); if(body) { var json = JSON.parse(body); ... }
java.util.Map<java.lang.String,java.lang.Object> getRequestHeaders()
Javascript example:
var headers = form.rest.getHeaders(); var contentType = headers["Content-Type"]; if(contentType == "application/json") { //parse json } ...
java.util.Map<java.lang.String,java.lang.Object> getPathParameters()
Javascript example:
var pathParms = form.rest.getPathParameters(); var customerId = pathParms.customerId; if(customerId) { //lookup customer } ...
java.util.Map<java.lang.String,java.lang.Object> getRequestParameters()
Javascript example:
var params = form.rest.getParameters(); var username = params.username; if(username) { //validate username } ...
void setResponseHeader(java.lang.String name, java.lang.String value)
Javascript example:
form.rest.setResponseHeader("Content-Type", "application/json");
void removeResponseHeader(java.lang.String name)
Javascript example:
form.rest.removeResponseHeader("Content-Type");
void setResponseStatus(int status)
status
- HTTP status code
Further documentation.
Javascript example:
form.rest.setResponseStatus(200);
void setResponseBody(java.lang.String responseBody)
responseBody
- the response body
Further documentation.
Javascript example:
var jsonStr = JSON.stringify(myObj); form.rest.setResponseBody(jsonStr);
java.lang.String getRequestContentType()
void setResponseContentType(java.lang.String contentType)
com.ebasetech.xi.services.auth.UserCredentials readBasicAuthenticationCredentials()
UserCredentials
from the HTTP Basic Access Authentication.
If the header does not exist in the HTTP request then a null object is returned, otherwise the username and password are extract from the header and used to populate the UserCredentials
object.
Javascript example:
var authenticated = false; var cred = form.rest.readBasicAuthenticationCredentials(); if(cred) { //authenticate user if(cred.getUsername() == "demouser" && cred.getPassword() == "demopwd") { authenticated = true; } else { //send back forbidden status form.rest.setStatus(403); } } else { //send back 401 status and WWW-Authenticate header form.rest.setResponseHeader("WWW-Authenticate", "Basic realm=\"My Realm\""); form.rest.setStatus(401); } if(authenticated) { // do something }