Built-in HTTP Components
InterSystems IRIS 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")
Do tPOSTJSON.%ToJSON(.tPOSTStream)
// 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)