Skip to content

Utils

Right now, the library offers only one utility method, but more could be added in the future if necessary.

DownloadJson

If you need to download JSON from an API without the need to pass headers or cookies to it, you can use the HttpGetJson method. It has two overloads:

public async Task<T?> HttpGetJson<T>(
string url,
CancellationToken token = default
);
public async Task<T?> HttpGetJson<T>(
string url,
string query,
CancellationToken token = default
);

The first one assumes that you pass the full URL, encoding the query string yourself:

var response = await HttpGetJson<object>(
"https://api.example.com/data?query=" + Uri.EscapeDataString("my query"),
token
);

The second one assumes that you pass the base URL and the query parameter value separately. In this case, the query parameter will be automatically encoded:

var response = await HttpGetJson<object>(
"https://api.example.com/data?query=",
"my query",
token
);

Both overloads accept a type parameter that represents the type you want to deserialize the JSON into.