KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Order of HTTPRequest callbacks
PRODUCT: 4D | VERSION: 19 R | PLATFORM: Mac & Win
Published On: October 3, 2022

In v19 R6, HTTP requests can be performed using the HTTPRequest class, and callbacks can be implemented using an HTTPRequest options class. When programming various callback functions into an options class, it is important to know the order in which each callback would be executed. If all functions are defined, below is the chain of callback events:

1) onHeaders
2) onData
3a) onError
3b) onResponse
4) onTerminate

Note that some callbacks (onHeaders and onTerminate) are always called, while others may never be executed, depending on the situation, such as onData if there is no body in the request. The onError and onResponse callbacks are 3a and 3b because if one occurs, the other does not. If an error occurs from the request, onError is executed and onResponse is skipped, and vice versa if an error does not occur.