KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: When to use simple objects vs cs.className objects in HTTPRequest
PRODUCT: 4D | VERSION: 19 R6 | PLATFORM: Mac & Win
Published On: September 19, 2022

In v19 R6, web requests can be performed by using 4D.HTTPRequest.new( ). The method accepts an options object as a second parameter. This object can be a simple object created with New object, or it can be an instance of a class created from cs.className.new( ). Passing an options object like this:

$obj:=New object("method"; "POST")
$request:=4D.HTTPRequest.new($url; $obj)

Is the same as passing an options object like this:

$obj:=cs.myClass.new("POST")
$request:=4D.HTTPRequest.new($url; $obj)

If the constructor for myClass was defined like this:

Class constructor($method : Text)
  This.method:=$method

Both will define the HTTP method for the request as “POST”, for example.

Since simple objects cannot have functions as property values, it is recommended to use classes when defining callback functions, such as onResponse, for requests. Otherwise, if the web request is a simple, one-off call, a simple object would suffice to define HTTP method, headers, and body.