Tech Tip: 4D HTTP Request Class Options
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: August 26, 2025
4D provided a new class to work with HTTP Requests. This class is the HTTPRequest class, which supersedes the use of the HTTP Request 4D command.
https://developer.4d.com/docs/API/HTTPRequestClass
When reviewing at the documentation, the class suggests that a custom class be implemented to build the options for the HTTP Request. A class can be useful if HTTP Requests will be used extensively throughout a database with various options, however it is not a requirement.
The options can simply be an object built for a specific call.
For example, with a simple GET request to google.com can be performed using the following:
var $request : 4D.HTTPRequest $request:=4D.HTTPRequest.new("google.com"; New object("method"; "GET")) $request.wait() |
The most commonly used options used would be the:
- "method" : This would be the type of HTTP request such as "GET", "POST", "PUT", ect.
- "headers" : If the request expects specific headers, an object could be built with the appropriate headers attributes and values.
- "body" : if the request expects data in the body this should also be created in the proper format such as a text or an object.
For more complex requests, it may be best to follow the documentation’s suggestion and build a class, as callback functions will be easier to implement and manage. However, this can also be achieved using an object with the Formula and/or Formula from string commands to define or apply a method as a callback function:
var $response : 4D.HTTPRequest var $HTTPRequestOptions : Object $HTTPRequestOptions:=New object("method"; "GET") $HTTPRequestOptions.onResponse:=Formula(ALERT("Complete")) $response:=4D.HTTPRequest.new("google.com"; $HTTPRequestOptions) $response.wait() |
The above takes the first example and implements the onResponse callback function which triggers when a response is received from the request. A simple ALERT is called in this case.
As shown, while it is recommended to use the HTTPRequest class over the legacy HTTP Request 4D command, it’s not as complicated as it may seem. Depending on the use case, options can be defined as a simple object or a class can be created to support more complex configurations