4D Blog

Home Product Managing HTTP Requests with HTTP Agents

Managing HTTP Requests with HTTP Agents

July 17, 2024

Product

In 4D 19 R6, we introduced HTTP classes to modernize syntax and enhance functionalities for our HTTP client commands. Building on this foundation, 4D 20 R6 brings a powerful new feature: HTTP agents. These agents empower developers to customize and optimize their connections to HTTP servers by managing connection persistence and reuse for HTTP requests.

HDI Managing HTTP Requests with HTTP Agents

Understanding HTTP Agents

If you have to perform multiple requests to the same HTTP server, you may want to optimize them for both the client and the server. One common way of doing that is to keep a single connection for all requests so you don’t have to negotiate a new connection between requests, especially a secured one. That’s when agents come into play, as agents handle the reuse of connections to optimize your requests.

First of all, it’s important to know that even if you don’t change anything in your code, you will benefit from agents: all your HTTPRequests will use a default agent if you don’t provide one. This agent will manage the persistence of your connections through a simple keep-alive mechanism, so when you send multiple requests to the same server, it will reuse connections if possible instead of creating a new one for each request.

This default agent is the simplest you can imagine, but you may (and should) want to create your own agent. Agents can allow you to fine-tune your connections, giving you control over the keep-alive mechanism, allowing you to choose the maximum number of concurrent connections to a specific server, adding timeouts to avoid keeping connections indefinitely or even configuring your TLS/SSL connections at agent level instead of doing it for each HTTPRequest.

Using an agent for an HTTPRequest is extremely easy; just use this bit of code:

var $requestOptions:={/*here you put the agent options*/}
var $myAgent:=4D.HTTPAgent.new($requestOptions)

var $requestOptions:={} 
$requestOptions.agent:=$myAgent
var $myRequest:=4D.HTTPRequest.new("www.4D.com"; $requestOptions)

Tip 1

HTTPAgent is a shared object. Consequently, you can add one to a singleton class to use the same agent for all your requests to the same server.

Tip 2

You can request multiple servers using the same agent. In that case, each server will have its own pool of connections using the same agent options.

With the agents, HTTP classes now cover all the functionalities of the HTTP commands and even more, so it’s a good moment to switch entirely to this new syntax. If you have any questions about HTTP classes or agents specifically, don’t hesitate to post them on the 4D forum.

Discuss

Tags 20 R6, 21, HTTP, Programming, Web

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Nicolas Brachfogel
Nicolas Brachfogel
Product Owner & Senior Developer - Nicolas Brachfogel joined 4D in 2017 as senior developer (4D Server and networking) and as Product Owner to manage the 4D version on Apple Silicon. He is tasked with the redaction of user stories and functional specifications, as well as the verification that the new features are in line with customers' needs. With a degree from Institut Supérieur d'Informatique Appliquée Paris (INSIA), Nicolas started his career as a software developer in 2001. After many years of development in Java and C++, he specialized himself in client-server development in the video game industry. As a developer/software architect, he worked on the server architectures of many games (Dofus Arena, Drakerz, Trivial Pursuit Go !).
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy