Section III – External Interfaces > External Interfaces > Application Server Relationship Bottom of Page
| Genesys 8.0 SCXML Technical Reference
External 2.0 Interfaces >

## Application Server Relationship

The following sections cover how the orchestration platform interfaces with an application server.

#### Mapping of the SCXML and Functional Module Elements to the HTTP Messages

The following sections cover the mapping of the SCXML and functional module element's attributes into the corresponding HTTP message elements.

##### Get/Delete message

###### `<fetch>` mapping

Here is an example of the `<fetch>` action:

    <session:fetch requestid="_data.reqid"
    		srcexpr="'http://www.business1.com/data2/content'" type="'plain-text'"
    		method="'get or delete'" timeout="'100'" maxstale="'10'" maxage="'20'">
    	<param name="'param1'" expr="'value1'"/>
    	<parm name="'p2'" expr="'v2'"/>
    </session:fetch>

Here is how it maps to an HTTP GET/DELETE message:

    GET/DELETE /data2/content? param1=value1&p2=v2 HTTP/1.1
    Host: www.business1.com
    Cache-Control: max-age=10, max-stale=10
    ...

Mapping Summary:

- The results of evaluating the `srcexpr` attribute yields the host and path elements of the HTTP message.
- The result of evaluating the child `<param>` elements yields the URL parameter list at the end of the path. Note that if the `srcexpr` attribute evaluates to a URL with URL parameters, we would concatenate the `<param>` element parameters to them. If the `<param>` element value is a complex object, the value is the result of evaluating the `toString()` function of that object, which is usually `[object object]`.
- The result of evaluating the `maxage` attribute yields the `Cache-Control` header with the `max-age` directive.
- The result of evaluating the `maxstale` attribute yields the `Cache-Control` header with the `max-stale` directive.
- The result of evaluating the `type` attribute yields the `Accept` header. Also the data type returned by the application server in the HTTP response will be checked against the type value. If it is different, an `error.session.fetch` will be raised — an exception that is `text-plain`, which means any type of returned value is accepted.
- There is no HTTP body for the GET request.

###### `<data>` mapping

Here is an example of the `<data>` action:

    <state id="bdataY" src="http://www.business1.com/parameters/dataY" />

Here is how it maps to an HTTP GET message:

    GET /parameters/dataY HTTP/1.1
    Host: www.business1.com
    Cache-Control: max-age=10, max-stale=10
    ...

Mapping Summary:

- The results of evaluating the `src` attribute yields the host and path elements of the HTTP message.
- The Cache-Control header with the `max-age` directive is set using the value configured by the orchestration platform.
- The Cache-Control header with the `max-stale` directive is set using the value configured by the orchestration platform.
- There is no HTTP body for the GET request.

###### `<response>` mapping

Here is an example of a positive `<response>` action:

    <ws:response requestid="_event.sendid">
    	<param name="'param1'" expr="'value1'"/>
    	<parm name="'p2'" expr="'v2'"/>
    	<parm name="'p3" expr="'v3'"/>
    </ws:response>

Here is how it maps to an HTTP GET Response message:

    HTTP/1.1 200
    Content-Type=application/json
    Content-Length=xx

    {"param1":"value1","p2":"v2","p3":{"a":4,"b":5}}
    ...

Here is an example of a negative `<response>` action:

    <ws:response requestid="_event.sendid" type="negative"
    		resultcode="invalidparameter">
    	<param name="'description" expr="'Invalid value for parm2"/>
    </ws:response>

Here is how it maps to an HTTP GET Response message:

    HTTP/1.1 500 invalidparameter
    Content-Type=application/json
    Content-Length=xx

    {"description":"Invalid value for parm2"}
    ...

Mapping Summary:

- The result of evaluating the `<param>` elements yields the body element formatted in JSON format, where each `<parameter>` name should appear as a top-level attribute. Note: the `Content-Length` header value will be set to the total length of the resulting body element.
- The `Content-Type` header value will always be "`application/json`".
- The `Status-Code` header value will either be "`200`" for positive responses or "`500`" for negative responses.
- The `resultcode` attribute will be mapped to the `Reason-Phrase` header element.

##### POST/PUT Message

###### `<fetch>` mapping

Here is an example of the `<fetch>` action with enctype = application/x-www-form-urlcoded:

    <session:fetch requestid="_data.reqid"
    		srcexpr="'http://www.business1.com/data2/content'" type="'plain-text'"
    		method="'post or put'" timeout="'100'" maxstale="'10'"
    		maxage="'20'" enctype="'x-www-form-urlcoded'">
    	<param name="'param1'" expr="'value1'"/>
    	<parm name="'p2'" expr="'v2'"/>
    	<parm name="'p3" expr="'v3'"/>
    </session:fetch>

Note: v3 has two properties: "a" and "b". v3.a = 4 and v3.b = 5.

Here is how it maps to an HTTP POST/PUT message:

    POST/PUT /data2/content HTTP/1.1
    Host: www.business1.com
    Cache-Control: max-age=10, max-stale=10
    Content-Type=application/x-www-form-urlencoded
    Content-Length=xx

    param1=value1&p2=v2&p3=[object object]
    ...

Here is an example of the `<fetch>` action with enctype = application/json:

    <session:fetch requestid="_data.reqid"
    		srcexpr="'http://www.business1.com/data2/content'" type="'plain-text'"
    		method="'post or put'" timeout="'100'" maxstale="'10'"
    		maxage="'20'" enctype="'application/json'">
    	<param name="'param1'" expr="'value1'"/>
    	<parm name="'p2'" expr="'v2'"/>
    	<parm name="'p3" expr="'v3'"/>
    </session:fetch>

Note: v3 has two properties "a" and "b". v3.a = 4 and v3.b = 5.

Here is how it maps to an HTTP POST/PUT message:

    POST/PUT /data2/content HTTP/1.1
    Host: www.business1.com
    Cache-Control: max-age=10, max-stale=10
    Content-Type=application/json
    Content-Length=xx

    {"param1":"value1","p2":"v2","p3":{"a":4,"b":5}}
    ...

Mapping Summary:

- The results of evaluating the `srcexpr` attribute yields the host and path elements of the HTTP message.
- The results of the `<param>` elements depend on the `enctype` attribute. Note: the `Content-Length` header value will be set to the total length of the resulting body element.
- `application/x-www-form-urlcoded` — The result of evaluating the `<param>` elements yields the body element in the format `p1=v1&p2=v2&p3=v3..., where p1, p2, p3,...` are the names in the `<param>` elements, and `v1`, `v2`, and `v3` are values that result from evaluating the corresponding `expr` attributes. If one of the values is not a simple type, we would put the result of the "`toString()`" function in the body, as in the `GET` case.
- `application/json` — The result of evaluating the `<param>` elements yields the body element formatted in JSON format, where each `<parameter>` name should appear as a top-level attribute.
- The result of evaluating the `maxage` attribute yields the `Cache-Control` header with the `max-age` directive.
- The result of evaluating the `maxstale` attribute yields the `Cache-Control` header with the `max-stale` directive.
- The result of evaluating the `enctype` attribute yields the `Content-Type` header value.
- The result of evaluating the `type` attribute yields the `Accept` header. Also the data type returned by the application server in the HTTP response will be checked against the type value. If it is different, an `error.session.fetch` will be raised — this exception is `text-plain`, which means any type of returned value is accepted.

###### `<response>` mapping

Here is an example of a positive `<response>` action:

    <ws:response requestid="_event.sendid">
    	<param name="'param1'" expr="'value1'"/>
    	<parm name="'p2'" expr="'v2'"/>
    	<parm name="'p3" expr="'v3'"/>
    </ws:response>

Here is how it maps to an HTTP POST Response message:

    HTTP/1.1 200
    Content-Type=application/json
    Content-Length=xx

    {"param1":"value1","p2":"v2","p3":{"a":4,"b":5}}
    ...

Here is an example of a negative `<response>` action:

    <ws:response requestid="_event.sendid" type="negative"
    		resultcode="invalidparameter">
    	<param name="'description" expr="'Invalid value for parm2"/>
    </ws:response>

Here is how it maps to an HTTP POST Response message:

    HTTP/1.1 500 invalidparameter
    Content-Type=application/json
    Content-Length=xx

    {"description":"Invalid value for parm2"}
    ...

Mapping Summary:

- The result of evaluating the `<param>` elements yields the body element formatted in JSON format, where each `<parameter>` name should appear as a top-level attribute. Note: the `Content-Length` header value will be set to the total length of the resulting body element.
- The `Content-Type` header value will always be "`application/json`".
- The `Status-Code` header value will either be "`200`" for positive responses or "`500`" for negative responses.
- The `resultcode` attribute will be mapped to the `Reason-Phrase` header element.

Section III – External Interfaces > External Interfaces > Application Server Relationship Top of Page
| Genesys 8.0 SCXML Technical Reference
External 2.0 Interfaces >