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
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body.
Returns
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
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body. A caller-supplied
Acceptheader replacesapplication/json. jsonOptionsJsonSerializerOptions?-
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
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body. A caller-supplied
Acceptheader replacesapplication/json. jsonOptionsJsonSerializerOptions?-
Options for parsing the response body.
Returns
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
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body. A caller-supplied
Acceptheader replacesapplication/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
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body. A caller-supplied
Acceptheader replacesapplication/xml.
Returns
Do.FetchText(string, FetchOptions?)
Decodes the successful response as text.
public static Task<string> FetchText(string url, FetchOptions? options = null)Parameters
urlstring-
The absolute request URL.
optionsFetchOptions?-
Optional method, headers, and body.
Returns
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
urlstring-
The absolute request URL.
pathAbsolutePath-
The destination file. Missing parent directories are not created.
optionsFetchOptions?-
Optional method, headers, and body.
Returns
- Task<AbsolutePath>
-
The destination file.