ApiClient Configurations Explained
On This Page
By default, path parameters become function parameters and collection variables in paths become instance variables of the ApiClient. This changes that and makes collection variables function parameters. Ex: "https://someurl.com/:pathVariable/{{someCllectionVariable}}". `pathVariable` will always be a function variable but this option gives you control over where `someCllectionVariable` goes.
private readonly string _somePathCollectionVariable; // Private variable
public async Task<List<Ticket>> GetTickets()
{
return await _httpClient.GetFromJsonAsync<List<Ticket>>($"{_somePathCollectionVariable}/ticket.php");
}
// No private Variable
public async Task<Stream> GetTickets(string somePathCollectionVariable) // Now a function parameter
{
return await _httpClient.GetFromJsonAsync<List<Ticket>>($"{somePathCollectionVariable}/ticket.php");
}
public async Task<Stream> GetTickets()
{
var response = await _httpClient.GetAsync("{_someVariable}/ticket.php");
return await response.Content.ReadAsStreamAsync();
}
public async Task<Stream> GetTickets(CancellationToken cancellationToken) // Now a function parameter
{
var response = await _httpClient.GetAsync("{someVariable}/ticket.php", cancellationToken);
return await response.Content.ReadAsStreamAsync(cancellationToken);
}
You have two attribute libraries that you can choose from.
System.Text.Json
Newtonsoft.Json
[JsonProperty]
System.Text.Json
Newtonsoft.Json
GetAsJsonAsync
GetAsNewtonsoftJsonAsync
Enabling this setting is a great way to ensure that you are handling all possible responses from an api. When you enable this setting, the
StatusCode
StatusCode
object
OneOf
You have full control over the type of
- ApiClient: Appear at the top of generated ApiClient, description comes from root item description.
- QueryParameters: Each variable in the generated Parameters class will have an xml summary based on the description of the query parameters.
- FormData: Same as before but for FormData.
- PathVariables: An xml param tag will be generated on the ApiClient function for each path variable.
- Request: An xml summary will be generated on the ApiClient function from the description of the postman request item.
try
{
// Request body
}
catch (HttpRequestException ex)
{
// Error Handling Sinks
throw;
}
try
{
// Request body
}
catch (HttpRequestException ex)
{
// Error Handling Sinks
return default;
}
Each
try
{
// Request body
}
catch (HttpRequestException ex)
{
// Error Handling Sinks
throw;
}
catch (Exception ex)
{
// Error Handling Sinks
throw;
}
catch (// CatchExceptionType ex)
{
_logger.LogError(ex); // Log Exception
Console.WriteLine(ex); // Console Writeline
Debug.WriteLine(ex); // Debug Writeline
// Error Handling Strategy
}
- Root: A root is any folder in a collection that has a request (including the root itself).
- Host: The host part of a URL is the domain name or IP address that indicates where the resources are served from.
- Authority: The authority component of a URL includes the authentication section, the host, and the port. In the URL-
"http://username:password@example.com:8080/path/to/file"
Authority:,"username:password@example.com:8080"
Host:."example.com"
- PerAuthorityPerFolder: An ApiClient will be created for each root, with a caveat being that if a root uses different authorities in it's requests, the requests will be regrouped into new roots based on authority.
- Useful when the postman collection is well organized and you want your ApiClients to have seperation of concerns
- PerAuthority: An ApiClient will be created for each authority disregarding the folders requests are in.
- Useful when the you want a monolithic ApiClient.
- Manual: Lets you decide how to requests get group.
- Best of both worlds but requires you to manually group roots.
- Root: A class that's not a member of any other class
- Non-Root: A class generated to be a member of another class.
- Json Example: A key-value pair in json. In this section, it generally refers to a key-value pair where the value is an object. Denoted by "{}" in value. "person" : { }
- Original Name: The value of the key in the json example.
- Duplicate: A json example who's members match every single member by type and name on a previously processed json example. And the original and potential duplicate have the exact same amount of properties.
- Semi-Duplicate: A json example who's members match every single member by type and name on a previously processed json example. And the original (already processed) has more properties than the potential duplicate.
Person2