Release Notes
2.0.3
Changes
LoggingHandlerlogs failed responses and request exceptions atInformationinstead ofError. The failed response is returned and the exception is rethrown, so the caller already logs the error where it is handled; logging it in the handler as well produced a duplicate error entry, which also reached alert sinks such as email and Slack for expected client errors like a 400. The exception is no longer attached to the entry; its message is logged instead
2.0.2
Target frameworks
Albatross.Httpnow multi-targetsnet8.0andnet10.0Microsoft.Extensions.Http,Microsoft.Extensions.Logging.AbstractionsandSystem.Text.Jsonupdated to10.0.12- SourceLink is referenced by the package project instead of
Directory.Build.props, so it no longer leaks into the sample and test projects
Fixes
AddLoggingHandlerusesTryAddTransient, so calling it more than once no longer registers duplicateLoggingHandlerinstancesExecuteno longer swallowsJsonExceptionwhen deserializing a successful response - a malformed body now surfaces as an exception instead of silently returning nullLoggingHandlerlogs request start and completion atInformationinstead ofDebug
2.0.1
Albatross.Exceptionsdependency moved from1.0.0-rc.21to the released1.0.0
2.0.0
Redesign of HTTP error handling around status-driven semantic exceptions. This release contains breaking changes.
Breaking changes
- The
TErrorgeneric parameter is gone from everyHttpClientExtensionsmethod.Execute<TResponse, TError>,ExecuteOrThrow<TResponse, TError>,ExecuteOrThrowStruct<TResponse, TError>,ExecuteAsStream<TItem, TError>andSend<TError>becomeExecute<TResponse>,ExecuteOrThrow<TResponse>,ExecuteOrThrowStruct<TResponse>,ExecuteAsStream<TItem>andSend ServiceException<T>has been removed. The library no longer deserializes the error response into a caller-supplied DTO; the raw body and its content type are captured instead and the caller decides how to interpret themServiceExceptionmoved to theAlbatross.Http.Exceptionsnamespace and is now thrown only for status codes that have no dedicated semantic exceptionExecuteOrThrowandExecuteOrThrowStructthrowMissingRequiredValueException<TResponse>rather thanServiceExceptionwhen a successful response carries no body
IHttpException
- Common interface implemented by every exception the library throws, exposing
Status,Method,Endpoint,ContentTypeandContent IHttpException.BuildMessagerenders the exception message as a JSON document. When the error body is itself a JSON object it is preserved andstatus,methodandendpointare merged in; a conflicting property in the body is never overwritten - the library's value is added under a numerically suffixed name such asstatus2. Any other body is wrapped in a new object undercontent
Semantic exceptions
The response status code alone decides the exception type. Each type derives from the framework or Albatross.Exceptions type that carries the same meaning, so callers can catch the semantic type without knowing the transport.
| Status | Exception | Base type |
|---|---|---|
| 400 | HttpArgumentException |
System.ArgumentException |
| 401 | HttpNotAuthenticatedException |
Albatross.Exceptions.NotAuthenticatedException |
| 403 | HttpForbiddenException |
Albatross.Exceptions.ForbiddenException |
| 404 | HttpNotFoundException |
Albatross.Exceptions.NotFoundException |
| 408 | HttpTimeoutException |
System.TimeoutException |
| 409 | HttpConflictException |
Albatross.Exceptions.ConflictException |
| 412 | HttpPreconditionFailedException |
Albatross.Exceptions.PreconditionFailedException |
| 422 | HttpValidationException |
Albatross.Exceptions.ValidationException |
| 501 | HttpNotSupportedException |
System.NotSupportedException |
| any other 400+ | ServiceException |
System.Exception |
MissingRequiredValueException<TResponse>derives fromAlbatross.Exceptions.MissingRequiredValueExceptionand is thrown when a successful response returns no content, or content that deserializes to null, where a value was required
HttpResponseContent
- Record carrying the raw
ContentandContentTypeof an error response IsJson()recognizesapplication/jsonas well as structured suffixes such asapplication/problem+json, and ignores parameters like; charset=utf-8
1.0.0
Initial release of Albatross.Http, a companion library for HttpClient providing extensions and shared types for HTTP client code generation.
DefaultJsonSerializerOptions
- Static class providing a shared
JsonSerializerOptionsinstance with camelCase naming policy, no indentation, andJsonIgnoreCondition.WhenWritingNull - Used as the default by
RequestBuilder
RequestBuilder
- Fluent builder for constructing
HttpRequestMessagewith support for:- JSON, plain text, stream, and form URL-encoded content
- Multipart form data with files (byte array and stream), string fields, and JSON fields
- Query string parameters (accepts nullable strings)
- Custom
JsonSerializerOptions
- Automatically resets after
Build()for reuse
RequestBuilderExtensions
AddQueryString<T>- generic method for any non-null valueAddQueryStringIfSet<T>(class constraint) - only adds query string if value is not null or emptyAddQueryStringIfSet<T>(struct constraint) - only adds query string if nullable value has a value, with automatic ISO8601 formatting forDateTime,DateOnly,TimeOnly, andDateTimeOffset
HttpClientExtensions
Execute<TResponse>andExecute<TResponse, TError>- send a request and deserialize the response, returning nullable resultSend<TError>- fire-and-forget method for requests that don't return a body but still need error handlingExecuteOrThrow<TResponse>andExecuteOrThrow<TResponse, TError>- guaranteed non-null response for reference types, throwsServiceExceptionon empty or null contentExecuteOrThrowStruct<TResponse>andExecuteOrThrowStruct<TResponse, TError>- guaranteed response for value types, internally deserializes asNullable<T>to detect null JSON valuesExecuteAsStream<TItem>andExecuteAsStream<TItem, TError>- streams the response asIAsyncEnumerable<TItem?>for endpoints usingyield returnorIAsyncEnumerable<T>, usingHttpCompletionOption.ResponseHeadersReadfor true streaming
UrlExtensions
CreateUrl- builds URLs with query string parameters fromNameValueCollectionCreateUrlArray- batches large array query parameters across multiple URLs using repeated keysCreateUrlArrayByDelimitedValue- batches array parameters using a delimiter within a single keyGetFullUri- resolves relative URIs against a base address- ISO8601 format constants and extension methods for
DateOnly,TimeOnly,DateTime, andDateTimeOffset
ServiceException
ServiceException<T>- typed exception carrying HTTP status code, method, endpoint, and a deserialized error objectServiceException- convenience subclass defaulting the error type tostring
LoggingHandler
DelegatingHandlerfor structured logging of HTTP requests and responses viaILogger- Logs request start, completion status, error response bodies, and cancellations
RegistrationExtensions
AddLoggingHandler- registersLoggingHandleras a transient serviceBuildDefault- configuresIHttpClientBuilderwith sensible defaults: removes built-in HTTP loggers, enables GZip/Deflate/Brotli automatic decompression, auto-redirect, and optional Windows default credentials with pre-authentication
ContentTypes
- MIME type constants for JSON, text, HTML, CSV, form, Excel, octet-stream, multipart form data, and images