Interface RESTfulService


public interface RESTfulService
  • Method Details

    • getEndpointPath

      java.lang.String getEndpointPath()
      Returns the name of the Enpoint path used to invoke the RESTful web service.
      Since:
      V5.2
    • getMethod

      java.lang.String getMethod()
      Returns the HTTP Method e.g POST, GET etc.. used to invoke the RESTful web service.
      Since:
      V5.2
    • getPathParameter

      java.lang.String getPathParameter​(java.lang.String parameter)
      Returns a path parameter based on the configured endpoint path parameter. The path parameters are configured by wrapping the name in braces e.g {customerId}

      Further documentation.

      Javascript example:

       
       var customerId = form.rest.getPathParameter("customerId");
       //get customer details
       ...
       
      Since:
      V5.2
    • getRequestParameter

      java.lang.String getRequestParameter​(java.lang.String parameter)
      Returns a parameter by a specific name. Further documentation.

      Javascript example:

       // get the parameter from the endpoint. 
       var username = form.rest.getParameter("username");
       //get user details
       ...
       
      Since:
      V5.2
    • getRequestHeader

      java.lang.String getRequestHeader​(java.lang.String header)
      Returns a request header by a specific name. Further documentation.

      Javascript example:

       //get the post parameter
       var username = form.rest.getRequestHeader("username");
       //get user details
       ...
       
      Since:
      V5.2
    • getRequestBody

      java.lang.String getRequestBody()
      Returns the request body. Further documentation.

      Javascript example:

       //get the post parameter
       var body = form.rest.getRequestBody();
       if(body)
       {
         var json = JSON.parse(body);
         ...
       }
       
       
       
      Since:
      V5.2
    • getRequestHeaders

      java.util.Map<java.lang.String,​java.lang.Object> getRequestHeaders()
      Returns all of the HTTP request headers as a JavaScript object Further documentation.

      Javascript example:

       var headers = form.rest.getHeaders();
       
       var contentType = headers["Content-Type"];
       if(contentType == "application/json")
       {
          //parse json
       }
       ...
       
      Since:
      V5.2
    • getPathParameters

      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.

      Javascript example:

       var pathParms = form.rest.getPathParameters();
       
       var customerId = pathParms.customerId;
       if(customerId)
       {
          //lookup customer
       }
       ...
       
      Since:
      V5.2
    • getRequestParameters

      java.util.Map<java.lang.String,​java.lang.Object> getRequestParameters()
      Returns all of the HTTP parameters as a JavaScript object Further documentation.

      Javascript example:

       var params = form.rest.getParameters();
       
       var username = params.username;
       if(username)
       {
          //validate username
       }
       ...
       
      Since:
      V5.2
    • setResponseHeader

      void setResponseHeader​(java.lang.String name, java.lang.String value)
      Sets a response header by name and value. Further documentation.

      Javascript example:

       form.rest.setResponseHeader("Content-Type", "application/json");
       
      Since:
      V5.2
    • removeResponseHeader

      void removeResponseHeader​(java.lang.String name)
      Removes a response header by name Further documentation.

      Javascript example:

       form.rest.removeResponseHeader("Content-Type");
       
      Since:
      V5.2
    • setResponseStatus

      void setResponseStatus​(int status)
      Sets the response status e.g 200 for OK
      Parameters:
      status - HTTP status code Further documentation.

      Javascript example:

       form.rest.setResponseStatus(200);
       
      Since:
      V5.2
    • setResponseBody

      void setResponseBody​(java.lang.String responseBody)
      Sets the response body
      Parameters:
      responseBody - the response body Further documentation.

      Javascript example:

       var jsonStr = JSON.stringify(myObj);
       form.rest.setResponseBody(jsonStr);
       
      Since:
      V5.2
    • getRequestContentType

      java.lang.String getRequestContentType()
      Returns the HTTP request content type Further documentation.
      Since:
      V5.2
    • setResponseContentType

      void setResponseContentType​(java.lang.String contentType)
      Sets the HTTP response content type Further documentation.
      Since:
      V5.2
    • readBasicAuthenticationCredentials

      com.ebasetech.xi.services.auth.UserCredentials readBasicAuthenticationCredentials()
      Returns the 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.

      Further documentation.

      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
       }
       
      Since:
      V5.2