Skip to main content

Built-in HTTP Components

InterSystems IRIS® data platform provides built-in business hosts that use the HTTP adapters, allowing you to add HTTP support to a production without creating a custom business service or business operation. If you need a business service that uses the HTTP inbound adapter, you can add EnsLib.HTTP.GenericServiceOpens in a new tab to the production. Similarly, a production that needs to leverage the HTTP outbound adapter can use EnsLib.HTTP.GenericOperationOpens in a new tab.

InterSystems IRIS also provides a message class designed to carry a HTTP request or response through a production. This message class, EnsLib.HTTP.GenericMessageOpens in a new tab, includes the headers and body of the HTTP request. In some cases, it may be useful to construct a EnsLib.HTTP.GenericMessage from scratch and then send it out using EnsLib.HTTP.GenericOperation. This process consists of building the body and populating the headers before creating the new message. The following is an example:

// Build the header
#dim tRESTHTTPHeaders
Set tRESTHTTPHeaders("HttpRequest")="POST"
Set tRESTHTTPHeaders("HTTPVersion")="1.1"

// Build the body
#dim tPOSTStream = ##class(%Stream.GlobalCharacter).%New()
#dim tPOSTJSON = {}
Set tPOSTJSON.projection = []
Do tPOSTJSON.projection.%Push("%Doc")

// Add more headers
Set tRESTHTTPHeaders("content-length") = tPOSTStream.Size
Set tRESTHTTPHeaders("content-type") = "application/json"

// Create message
Return ##class(EnsLib.HTTP.GenericMessage).%New(tPOSTStream,,.tRESTHTTPHeaders)

More About Message Headers

The following is an example of what the headers of a EnsLib.HTTP.GenericMessage might look like if it were created by InterSystems IRIS:

  <HTTPHeadersItem HTTPHeadersKey="CharEncoding" xsi:nil="true"></HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="EnsConfigName">ForDocker</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="HTTPVersion">1.1</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="HttpRequest">POST</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="IParams">0</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="RawParams" xsi:nil="true"></HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="TranslationTable">RAW</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="URL">/api/atelier/v4/TEST/action/query</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="accept">application/json, text/plain, */*</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="connection">close</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="content-length">127</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="content-type">application/json</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="cookie">CSPSESSIONID-SP-42773-UP-api-atelier-=001000000000t7LT7VX9SXUNIM7S8yKxK44S$uBbUtzNHVjIAk</HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="host"></HTTPHeadersItem>
  <HTTPHeadersItem HTTPHeadersKey="user-agent">axios/0.21.1</HTTPHeadersItem>

If you are building a EnsLib.HTTP.GenericMessage from scratch, not all of these headers are required. At a minimum, the HttpRequest, HTTPVersion, and content-type headers should be defined, and the content-length header is also commonly defined.

When a production uses EnsLib.HTTP.GenericOperation, the URL header of the message is processed in conjunction with the URL property of the outbound adapter to determine the URL path of the request. Like other adapter properties, this URL property is set by using the Management Portal to define the URL setting of the production’s business operation. For details on how the URL header and the URL property interact, refer to the class reference for the adapter’s URL propertyOpens in a new tab.

When creating the HTTP message using EnsLib.HTTP.GenericMessage.%New(), you have several options for passing in the headers. Commonly, the header argument is passed in as an array. However, the %New method also accepts headers as an ObjectScript array reference, an %AbstractStream with its own Attributes to copy from, an %Net.HttpResponse object with its own Headers to copy from, or a string of the form 'a=1,b=2,c=3'.

FeedbackOpens in a new tab