Table of Contents

HTTP requests

Send HTTP requests, read JSON, XML, or text responses, and download files.

Entry points

Do.Fetch(string, FetchOptions?)

Sends an HTTP request immediately and buffers its response.

public static FetchRequest Fetch(string url, FetchOptions? options = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body.

Returns

FetchRequest

Do.FetchJson<T>(string, FetchOptions?, JsonSerializerOptions?)

Requests JSON and deserializes the successful response into the requested value type.

public static Task<T?> FetchJson<T>(string url, FetchOptions? options = null, JsonSerializerOptions? jsonOptions = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body. A caller-supplied Accept header replaces application/json.

jsonOptions JsonSerializerOptions?

Options for deserializing the response body.

Returns

Task<T?>

Type Parameters

T

Do.FetchJson(string, FetchOptions?, JsonSerializerOptions?)

Requests JSON and reads the successful response as a JSON document model.

public static Task<JsonNode?> FetchJson(string url, FetchOptions? options = null, JsonSerializerOptions? jsonOptions = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body. A caller-supplied Accept header replaces application/json.

jsonOptions JsonSerializerOptions?

Options for parsing the response body.

Returns

Task<JsonNode?>

Do.FetchXml<T>(string, FetchOptions?)

Requests XML and deserializes the successful response into the requested value type.

public static Task<T?> FetchXml<T>(string url, FetchOptions? options = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body. A caller-supplied Accept header replaces application/xml.

Returns

Task<T?>

Type Parameters

T

Do.FetchXml(string, FetchOptions?)

Requests XML and reads the successful response as an XML document model.

public static Task<XDocument> FetchXml(string url, FetchOptions? options = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body. A caller-supplied Accept header replaces application/xml.

Returns

Task<XDocument>

Do.FetchText(string, FetchOptions?)

Decodes the successful response as text.

public static Task<string> FetchText(string url, FetchOptions? options = null)

Parameters

url string

The absolute request URL.

options FetchOptions?

Optional method, headers, and body.

Returns

Task<string>

Do.FetchFile(string, AbsolutePath, FetchOptions?)

Streams the successful response body to a file, replacing any existing file.

public static Task<AbsolutePath> FetchFile(string url, AbsolutePath path, FetchOptions? options = null)

Parameters

url string

The absolute request URL.

path AbsolutePath

The destination file. Missing parent directories are not created.

options FetchOptions?

Optional method, headers, and body.

Returns

Task<AbsolutePath>

The destination file.

Related types