Configuration
As for most libraries targeting the newest .NET Core components, this library exposes extension methods that help attach the configuration to the service collection.
The client
variable passed to the configuration delegate is of type IHubSpotClientConfigurator
and can be used to
customize how the
HttpClient
is crated by the internalIHttpClientFactory
register internal services
Additional extension methods to the IHubSpotClientConfigurator
type are available and can be added.
Configure the base address
By default, the client is configured to target the HubSpot REST API endpoint, https://api.hubapi.com.
For development and/or troubleshooting reasons, it is possible to override this setting by using the SetBaseAddress
method.
Configure the serialization settings
By default, the client is configured to serialize the payloads according to HubSpot REST API's guidelines.
In case of need, it's possible to customize the default setup by using the ConfigureSerialization
method.
Configure the HTTP client
In case of need, it's possible to customize the HttpClient
used to perform the HTTP requests to the HubSpot API.
For this, it's possible to use the ConfigureHttpClient
method.
Configure the HTTP client factory
The HttpClient
factory API allows the creation of complex chains of handlers that can be used to enrich and inspect the outgoing HTTP request.
Use cases range from adding support for tracers like AWS X-Ray or a transient-fault-handling library like Polly.
Sample: Configuring AWS X-Ray tracing.
The snippet below shows how to instruct the HTTP client factory to decorate clients with the AWS X-Ray tracing handler.
Sample: Configuring a Polly policy
The snippet below shows how to instruct the HTTP client factory to decorate clients with a retry policy created with Polly.
Authentication
HubSpot's APIs allow two means of authentication: OAuth and API keys.
While most endpoints support both methods (unless the documentation for a specific endpoint says otherwise), OAuth is generally recommended.
This library supports both types.
OAuth authentication
OAuth is used to require an authorization token to be used to sign successive requests.
The whole flow is automatically handled via a message handler added to the HttpClient pipeline.
The snippet below shows how to register the OAuth message handler.
In the snippet, we are assuming that the following fields are available through the Microsoft Configuration subsystem, under the parent key HubSpot
:
HubSpot:ClientId
HubSpot:SecretKey
HubSpot:RedirectUri
HubSpot:RefreshToken
API key authentication
API keys are good for rapid prototyping or integrations designed for single-account use. HubSpot API requires the API key to be added as a query string parameter whose key is hapikey
.
This library takes care of properly attaching the API key to the outgoing requests via a message handler added to the HttpClient pipeline.
The snippet below shows how to register the API key message handler.
In the snippet, we are assuming that the API key is available through the Microsoft Configuration subsystem, under the parent key HubSpot
with the name ApiKey
: HubSpot:ApiKey
.
Daisy chaining
The configuration API supports daisy chaining of methods.
Last updated