HTTP

HTTP Module JavaScript API

The HTTP Module allows you to create HTTP and HTTPS requests as HTTPRequest objects, send them, and use their responses as HTTPResult objects.
 

HTTP

The HTTP module exposes methods for creating HTTPRequest objects.

Methods

create(method: string, uri: string): HTTPRequest

Creates an HTTPRequest from the provided HTTP request method and resource URI.

var request = HTTP.create('GET', 'https://daas.caristix.com/fhir_r4/Patient');

createFromNetworkConnection(method: string, connection: NetworkConnection, path: string): HTTPRequest

Creates an HTTPRequest from the provided HTTP request method, NetworkConnection object and resource URL path. Request host, client certificate and timeout are obtained from the NetworkConnection.

var connection = NetworkConnections.getConnection('DaaS Caristix FHIR R4 Server');
var requestFromConnection = HTTP.createFromNetworkConnection('GET', connection, '/Patient');

 

HTTPRequest

This object exposes properties and methods to edit and send an HTTP request.

Properties

method: string

The HTTP method used by the request, as defined when creating the request.

var method = request.method;
// The value should be equal to "GET".

uri: string

The fully-qualified URI of the request, as defined when creating the request.

var uri = request.uri;
//The value should be equal to "https://daas.caristix.com/fhir_r4/Patient"

Methods

send(): HTTPResult

Sends the request and returns the result.

var result = request.send();

setBody(body: string): void

Sets the request’s body to the provided string.

request.setBody('MSH|^~\&|');
//The request's body should be equal to "MSH|^~\&|"

setTimeout(timeout: number): void

Sets the request’s timeout in seconds to the provided amount. The default value is 30 seconds.

request.setTimeout(5);
//The request's timeout should be equal to 5 seconds.

setCertificate(serialNumber: string): void

Sets the request’s Client Certificate using the provided serial number.

request.setCertificate('7571563212351');

setHeader(header: string, value: string): void

Adds an HTTP header to the request.

request.setHeader('accept', 'application/json');
//The request should contain the "Accept" header with value "application/json"

 

HTTPResult

This object exposes properties to read an HTTP response’s body and status code.

Properties

body: string

The response’s body.

var body = result.body;

statusCode: number

The response’s HTTP status code.

var status = result.statusCode;
var succeeded = status == 200;