3.2Creating a Builder Instance

Created on Aug 17, 2026~8 min read

The constructor of the HttpRequestBuilder type is designed to be private, so it cannot be instantiated directly using the new keyword. However, it provides multiple static methods to conveniently create instances of HttpRequestBuilder.

1. Using request verb static methods (recommended)

HttpRequestBuilder provides a variety of static methods based on HTTP request methods (such as GET, POST, etc.) for quickly creating instances. These methods support overloads to accommodate different parameter requirements.

cs
var httpRequestBuilder = HttpRequestBuilder.Get("https://furion.net/"); // GET request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Put("https://furion.net/"); // PUT request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Post("https://furion.net/"); // POST request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Delete("https://furion.net/"); // DELETE request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Options("https://furion.net/"); // OPTIONS request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Trace("https://furion.net/"); // TRACE request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Patch("https://furion.net/"); // PATCH request, supports multiple overloadsvar httpRequestBuilder = HttpRequestBuilder.Query("https://furion.net/"); // QUERY request, supports multiple overloads

2. Using the Create static method

The Create method allows you to create a HttpRequestBuilder instance in a more flexible way, supporting direct specification of the request method and URL, or the use of a custom HttpMethod.

cs
var httpRequestBuilder = HttpRequestBuilder.Create("GET", "https://furion.net/");var httpRequestBuilder = HttpRequestBuilder.Create(HttpMethod.Get, "https://furion.net/");// Custom request verb, such as a CONNECT requestvar httpRequestBuilder = HttpRequestBuilder.Create("Connect", "https://furion.net/");

3. Using the Setup static property

Setup returns a blank HttpRequestBuilder instance, specifically used to configure HttpRequestBuilder and pass it as an Action<HttpRequestBuilder> delegate to verb shortcut methods (such as GetAsync, PostAsync, etc.). It automatically converts chained configuration into a delegate through implicit conversion, eliminating the builder => builder wrapping.

cs
// Traditional approach: builder => builderawait httpRemoteService.GetAsync("https://furion.net/", builder => builder.UseETag().Profiler());// ✅ Using Setup insteadawait httpRemoteService.GetAsync("https://furion.net/", HttpRequestBuilder.Setup.UseETag().Profiler());

4. Using the FromCurl static method

By passing in a native cURL command string, FromCurl can generate a fully configured HttpRequestBuilder instance in one step, saving the tedious steps of manually calling various configuration methods.

cs
// Parse the simplest cURL command, automatically recognizing the GET methodvar httpRequestBuilder = HttpRequestBuilder.FromCurl("curl http://example.com");// Parse a command with a request body (-d), automatically inferred as POSTvar httpRequestBuilder = HttpRequestBuilder.FromCurl(    "curl -X POST https://api.furion.net/data -H \"Content-Type: application/json\" -d '{\"name\":\"John\"}'");
  • curlCommand: the complete cURL command string, which must start with curl.
  • configure: optional delegate used to register custom flag extractors.

5. Using the FromJson static method

By passing in a JSON configuration string, FromJson can generate a fully configured HttpRequestBuilder instance in one step, saving the tedious steps of manual chained calls.

cs
// Parse the simplest JSON configuration, automatically recognizing the GET methodvar httpRequestBuilder = HttpRequestBuilder.FromJson("""    {        "url":"http://example.com",        "method":"GET"    }    """);// Parse a JSON configuration with a request body, automatically inferred as POSTvar httpRequestBuilder = HttpRequestBuilder.FromJson("""    {        "url": "https://api.furion.net/data",        "method": "POST",        "headers": {            "Content-Type": "application/json"        },        "data": {            "name": "John"        }    }    """);
  • json: the complete JSON configuration string, which must be a JSON object (starting with { and ending with }); property names are case-insensitive and trailing commas are allowed.
  • configure: optional delegate used to register custom JSON field extractors.