Retrieve HTTP headers
You can retrieve HTTP headers in your REST operation. There are two methods for doing this.
You can retrieve the header using the WSHeader attribute as part of a function parameter, or you can retrieve headers via WSContext.
The option you choose depends on your requirements:
- If you want the header to be part of the REST operation to implement logic on the server or
client, you can pass data via headers you customize using WSHeader and WSName attributes in your function
parameter. For example, the remote address can be passed in a customized HTTP header by
specifying an input parameter with these
attributes:
You can display the remote address in your function using the statementip_address STRING ATTRIBUTES(WSHeader, WSOptional, WSName = "X-FourJs-Environment-Variable-REMOTE_ADDR")
DISPLAY ip_address
. In case the header is not present, you must also set the WSOptional attribute. - If you do not want the header to be part of the REST operation, you can use the WSContext mechanism. For example, the remote
address and server name can be retrieved by setting a context dictionary variable at the modular
level with the
WSContext
attribute. This allows you to retrieve allX-FourJs-Environment-xxx
set by the GAS by referencing a dictionary key value for the environment variable.In the following example, the dictionary type variable (context) is set with the attributeWSContext
:PRIVATE DEFINE context DICTIONARY ATTRIBUTES(WSContext) OF STRING DISPLAY context["Variable-REMOTE_ADDR"] -- displays the remote ADDR if set by the GAS DISPLAY context["Variable-SERVER_NAME"] -- displays the server name if set by the GAS