a!httpResponse() Function

Returns an HTTP Response object for use in a Web API.

Syntax

a!httpResponse( statusCode, headers, body )

  • statusCode (Number(Integer)): The status code of the response. Default is "200" meaning successful completion of the request.

  • headers (List of HttpHeader): A list of headers for the response. Built with a!httpheader(). Header values set using a!scsField() will be ignored.

  • body (Text): The body of the response. This value can be either text or a document. If a document is supplied, default headers will be set and the client browser will attempt to open the document. Some documents, such as images, sound files, and PDFs, can be effectively viewed within your browser window. Other documents, such as Microsoft Office files, may be downloaded for local viewing.

Returns

HTTP Response

Examples

To test these examples, paste them into the expression editor of a Web API object. You can view the test results from within the designer by clicking the Test Request button. You can also view the runtime results in your browser by clicking the URL.

Returning a JSON Body

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
a!httpResponse(
  statusCode: 200,
  headers: {
    a!httpHeader(name: "content-type", value: "application/json")
  },
  body:{
    {
      firstName: "Jane",
      lastName: "Doe",
      age: 35
    },
    {
      firstName: "John",
      lastName: "Smith",
      age: 42
    }
  }
)

Returning a Document as the Body

1
2
3
4
5
6
7
8
a!httpResponse(
  statusCode: 200,
  headers: {
    a!httpHeader(name: "content-type", value: "application/json")
  },
  body: a!iconIndicator("STATUS_WARN")
)

See also: Web APIs, a!httpheader()

Open in Github

On This Page

FEEDBACK