JSON response builder

[io/http/server/utils/JSON response builder]

Builds a JSON response structure out of its components: HTTP status, headers, and JSON data. Example:

  1. 200@1 received via status

  2. {"Content-Type": "text/plain"}@1 received via headers

  3. {"result": OK"}@1 received via data

  4. Sent out via response:

  "status": 200, "headers": {<br>
    "Content-Type": "text/plain"<br>
  "body": "{\"result\": \"OK\"}"<br>


__Keywords__: construct, build, response, http, API, text, REST, JSON

### Input ports

* __data__: ` any `

    Receives the JSON body of the response.<br>
    Example: {"result": "OK"}<br>

* __status__: ` number `

    Receives a HTTP status code.<br>
    Example: `200`<br>

* __headers__: ` {string: string} `

    Receives a record of HTTP headers.<br>
    {"Contanet-Type": "text/plain"}<br>

### Output ports

* __response__: 
    {"status": number, "headers": {string: string}, "body": string}

    [Inherited from port `response` of `response builder`] <br>
    Sends the constructed HTTP response.<br>

* __error__: ` {"error": string} `

    Sends error when JSON serialization failed.<br>

Last updated