HTTP Request (PRIM_WEB.HttpRequest)

HTTP request to an external web resource

Ancestors - Object (PRIM_OBJT)


An HTTPRequest allows access to 3rd party HTTP services, allowing LANSA to integrate with other web services.
An HTTPRequest is effectively a standard XMLHttpRequest in JavaScript.
HTTPRequests should be defined within the routine in which they are going to execute. This will create a new instance every time one is executed. The corresponding event routines for the Completed and Failed events are coded in the same routine.
The LANSA runtime maintains the instances until they have finished. This allows the same routine to be execute many times and many requests to execute, each one independently producing results.
If the HTTPRequest exists as a global scope, there will only ever be one instance.
HTTPRequest instances can't be defined with an EVTROUTINE as events cannot have other child events routines.


In this example, a weather API is executed asynchronously, returning the data as a JSON object.
When the completed event fires, the result is processed.
Mthroutine Name(GetWeather) Access(*Private)
   Define_Map For(*Input) Class(#prim_alph) Name(#Resource)
   Define_Com Class(#PRIM_WEB.HttpRequest) Name(#Request)
   #Request.URL := "" + #Resource
   Evtroutine Handling(#Request.Completed)
      If (#Request.Response *IsNot *null)
      Case (#Request.Response.Status)
      When (= 200)
         #Com_owner.Update( #Request.Response.JSON.RootItem )
         #Com_owner.UpdateForFailure( #Request )


Name Description
ComponentClassName ComponentClassName is the name of the component's class. Inherited from Object (PRIM_OBJT)
ComponentMembers ComponentMembers provides access to all the member components of this component Inherited from Object (PRIM_OBJT)
ComponentPatternName ComponentPatternName is used to qualify the class of the component. Inherited from Object (PRIM_OBJT)
ComponentTag Generic space allowing a value to be stored for the instance Inherited from Object (PRIM_OBJT)
ComponentType ComponentType gives you access to the type information about the component Inherited from Object (PRIM_OBJT)
ComponentTypeName ComponentTypeName is the fully qualified name of the component's class. Inherited from Object (PRIM_OBJT)
Content The content of an HTTP request
Headers HTTP Headers
Method Standard HTTP request methods such as GET, POST etc.
Name Name identifies the component Inherited from Object (PRIM_OBJT)
Owner Owner owns this component Inherited from Object (PRIM_OBJT)
Parent The component instance to which this instance is attached. The visual container for a control or the collector of a set of child instances Inherited from Object (PRIM_OBJT)
Response Reference to an HTTP Response object returned by the request
Status Standard HTTP request status code
Timeout Standard HTTP request timeout
Url URL of the request


Name Description
Completed Fired when the HTTP request returns after processing successfully
CreateInstance CreateInstance is signalled when an instance of a component is created Inherited from HTTP Request (PRIM_WEB.HttpRequest)
DestroyInstance DestroyInstance is signalled when an instance of a component is about to be destroyed Inherited from HTTP Request (PRIM_WEB.HttpRequest)
Failed Fired when the HTTP request returns after processing unsuccessfully


Name Description
Cancel Cancel the HTTP request
Execute Execute the Request synchronously
ExecuteAsync Execute the request asynchronously

See also

All Component Classes

Technical Reference

LANSA Version 15, April 2020