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. This page briefly introduces them, as well as the generic HTTP message class.
Generic HTTP Message Class
InterSystems IRIS 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.GenericMessageOpens in a new tab from scratch and then send it out using EnsLib.HTTP.GenericOperationOpens in a new tab. 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)
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 %AbstractStreamOpens in a new tab with its own Attributes to copy from, an %Net.HttpResponseOpens in a new tab object with its own Headers to copy from, or a string of the form 'a=1,b=2,c=3'.
URL Parameters
By default, URL parameters are sent in the HTTP request body. To force URL parameters to be sent in the URL, set the RawParams HTTP header. (If the IParams header is specified, then that will be used if the RawParams header is empty.)