REST annotation

The REST annotation supports access of REST services.

Package

eglx.rest

Comments

The fields in the REST annotation are as follows:

method eglx.http.HttpMethod?
Identifies the HTTP method used to invoke the REST service. Specify one of the following values:
  • _GET
  • POST
  • _DELETE
  • PUT
requestCharSet string
The character encoding for the request message. The default value is "UTF-8".

The requestFormat value specifies how to serialize an EDT data format, and the requestCharSet value determines how to convert the resulting string to bytes.

requestContentType string?
The content type on the request message. The default value is based on the value of requestFormat:
  • If the requestFormat value is XML, the default requestContentType value is "application/xml".
  • If JSON, "application/json".
  • If FORM, "application/x-www-form-urlencoded".
  • Otherwise, the default value of requestContentType is "text/html".
requestFormat eglx.services.Encoding?
A value that indicates the format of the representation that is sent to the service:
  • XML, to indicate that the format is Extensible Markup Language.
  • NONE, to indicate that the representation is a string, or a value that is compatible with a string, and is sent as is.
  • JSON, to indicate that the format is JavaScriptâ„¢ Object Notation.
  • FORM, to indicate that the format is form data, which is a record composed of argument-value pairs. In the following example of the content sent to the service, each pair is separated from the next by an ampersand (&):
    division=Consumer&dept=Sales
    For a given field in the Record part that is the basis of form data, you can specify the FormName property. You can use that property to work with an argument name that is an EGL reserved word or is not valid in EGL. Here is an example use of the FormName property:
    record anyRecord
       continue boolean {FormName="continue-content"};
    end
    The runtime code uses the value of the FormName property as the name of the argument transmitted to the service. Here is a representation that might be sent to the service:
    continue-content=yes

    The default value of the FormName property is the name of the record field. In this example, the default is continue.

    You cannot override the value of the FormName property when you declare a record that is based on the Record part.

If the representation is a record, the following statements apply:
  • The default value of requestFormat is XML.
  • JSON is also valid.
  • FORM is valid only if every field in the record is of type STRING or is of a type that is assignment-compatible with STRING. FORM is not valid if the record references another record.
responseCharSet string?
The character encoding for the response message. This encoding determines how to convert bytes to a string; and the responseFormat value determines how to convert that string to an EDT data format.
responseFormat eglx.services.Encoding?
A value that indicates the format of the representation that is returned from the service to the browser. The value is used by the browser runtime to convert the data into EDT data objects such as records and handlers. Here are the options:
  • XML, to indicate that the returned representation is in XML format.
  • NONE, to indicate that the returned representation is a string.
  • JSON, to indicate that the returned representation is in JSON format.
  • USE_CONTENTTYPE, to indicate that the value of the returned HTTP Content-Type header determines how to disassemble the representation. If you select this value, the header value must be "application/json" or "application/xml".

If the return value in the function prototype is a string or a value that is compatible with a string, the default value of responseFormat is NONE, which is the only valid format. If the return value is a record, the default value of responseFormat is XML, and JSON is also valid.

uriTemplate string?
A string, or template, that in most cases outlines a relative URI, which identifies the last qualifiers in the URI that are used to access the service. For background information, see the section on "REST for the EGL developer" in the following external web site:
The first URI qualifiers is called the base URI, which you can set in a resource-binding entry in your deployment descriptor.

If you do not set the base URI, the value of the uriTemplate field includes the complete URI. In most cases, the value of the uriTemplate property has two aspects:

  • The value of the uriTemplate field can include a constant value. Those characters are present in or after every URI that is used to access the service. The constant value might be as follows:
       /GetWeatherByZip?zipcode= 
    If the example is changed to include a path variable instead of a query string, the constant value is as follows:
       /GetWeatherByZip/
  • The value of the uriTemplate property can include query strings and path variables. Here is a query string:
       {zipcode}
    For example, after a query string is resolved, here is the relative URI and value that are used to access the service:
    /GetWeatherByZip?zipcode=02135
    If the template includes a path variable instead of a query string, here are the relative URI and value:
    /GetWeatherByZip/02135

    The EGL runtime code automatically completes a URI encoding on each substitution value that is specified in a service invocation statement, with one exception.

    For example, if your service-invocation statement indicates that the value for a given substitution variable is "Jeff Smith", the EGL runtime code converts the string to "Jeff%20Smith" so that the URI is valid. However, if the value of a substitution value begins with http://, the EGL runtime code does no URI encoding because the service-invocation statement is specifying an argument that provides a complete URI. If you are responsible for URI encoding, review the documentation on the HttpLib.convertToURLEncoded system function.

The default value of the uriTemplate field is an empty string so that, by default, you can specify the complete URI by setting the base URI.

Compatibility

Table 1. Compatibility
Target Issue
Javaâ„¢ Service access is not supported.
JavaScript No issues.