Click or drag to resize

JsonClient Class

Implements a light-weight JSON oriented HTTP client.
Inheritance Hierarchy
SystemObject
  Neon.NetJsonClient

Namespace:  Neon.Net
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.2.0
Syntax
public class JsonClient : IDisposable

The JsonClient type exposes the following members.

Constructors
  NameDescription
Public methodJsonClient(HttpClient)
Used in special situations (like ASP.NET Blazor) where a special HttpClient needs to be created and provided.
Public methodJsonClient(HttpMessageHandler, Boolean)
Used to construct a client for most situations, optionally specifying a custom HttpMessageHandler.
Top
Properties
  NameDescription
Public propertyBaseAddress
The default base Uri the client will use when relative URIs are specified for requests.
Public propertyDefaultRequestHeaders
Returns the base client's default request headers property to make it easy to customize request headers.
Public propertyDocumentType
Specifies the MIME type to use posting or putting documents to the endpoint. This defaults to the standard application/json but some services may require custom values.
Public propertyHttpClient
Returns the underlying HttpClient.
Public propertySafeRetryPolicy

The IRetryPolicy to be used to detect and retry transient network and HTTP errors for the safe methods. This defaults to ExponentialRetryPolicy with the transient detector function set to NetworkOrHttp(Exception).

Note Note
You may set this to null to disable safe transient error retry.
Public propertyTimeout
The default base Uri the client will use when relative URIs are specified for requests.
Public propertyUnsafeRetryPolicy

The IRetryPolicy to be used to detect and retry transient network errors for the unsafe methods. This defaults to NoRetryPolicy.

Note Note
You may set this to null to disable unsafe transient error retry.
Top
Methods
  NameDescription
Public methodDeleteAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP DELETE ensuring that a success code was returned.
Public methodDeleteAsync(IRetryPolicy, String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP DELETE using a specific IRetryPolicy and ensuring that a success code was returned.
Public methodDeleteAsyncTResult(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP DELETE returning a specific type and ensuring that a success cxode was returned.
Public methodDeleteUnsafeAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP DELETE without ensuring that a success code was returned.
Public methodDeleteUnsafeAsync(IRetryPolicy, String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP DELETE using a specific IRetryPolicy and without ensuring that a success code was returned.
Public methodDispose
Releases all resources associated with the instance.
Protected methodDispose(Boolean)
Releases all associated resources.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Finalizer.
(Overrides ObjectFinalize.)
Public methodGetAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP GET ensuring that a success code was returned.
Public methodGetAsync(IRetryPolicy, String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP GET using a specific IRetryPolicy" and ensuring that a success code was returned.
Public methodGetAsyncTResult(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP GET returning a specific type and ensuring that a success code was returned.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetUnsafeAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP GET without ensuring that a success code was returned.
Public methodGetUnsafeAsync(IRetryPolicy, String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP GET using a specific IRetryPolicy and without ensuring that a success code was returned.
Public methodHeadAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP HEAD ensuring that a success code was returned.
Public methodHeadAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP HEAD using a specific IRetryPolicy and ensuring that a success code was returned.
Public methodHeadAsyncTResult(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP HEAD returning a specific type and ensuring that a success code was returned.
Public methodHeadUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP HEAD without ensuring that a success code was returned.
Public methodHeadUnsafeAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP HEAD using a specific IRetryPolicy and without ensuring that a success code was returned.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodOptionsAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP OPTIONS ensuring that a success code was returned.
Public methodOptionsAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP OPTIONS using a specific IRetryPolicy and ensuring that a success code was returned.
Public methodOptionsAsyncTResult(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP OPTIONS returning a specific type and ensuring that a success code was returned.
Public methodOptionsUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP OPTIONS without ensuring that a success code was returned.
Public methodOptionsUnsafeAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP OPTIONS using a specific IRetryPolicy and without ensuring that a success code was returned.
Public methodPatchAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PATCH ensuring that a success code was returned.
Public methodPatchAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PATCH using a specific IRetryPolicy and ensuring that a success code was returned.
Public methodPatchAsyncTResult(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PATCH returning a specific type and ensuring that a success code was returned.
Public methodPatchUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PATCH without ensuring that a success code was returned.
Public methodPatchUnsafeAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PATCH using a specific IRetryPolicy and without ensuring that a success code was returned.
Public methodPostAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP POST ensuring that a success code was returned.
Public methodPostAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP POST using a specific IRetryPolicy and ensuring that a success code was returned.
Public methodPostAsyncTResult(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP POST returning a specific type and ensuring that a success code was returned.
Public methodPostUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP POST without ensuring that a success code was returned.
Public methodPostUnsafeAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP POST using a specific IRetryPolicy and without ensuring that a success code was returned.
Public methodPutAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PUT ensuring that a success code was returned.
Public methodPutAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PUT using a specific IRetryPolicy" and ensuring that a success code was returned.
Public methodPutAsyncTResult(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PUT returning a specific type and ensuring that a success code was returned.
Public methodPutUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PUT without ensuring that a success code was returned.
Public methodPutUnsafeAsync(IRetryPolicy, String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity)
Performs an HTTP PUT using a specific IRetryPolicy" and without ensuring that a success code was returned.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

Use GetAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), PutAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), PostAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), DeleteAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), OptionsAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), HeadAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), or PatchAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity) to perform HTTP operations that ensure that a non-error HTTP status code is returned by the servers.

Use GetUnsafeAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), PutUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), PostUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), DeleteUnsafeAsync(String, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), OptionsUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), HeadUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity), or PatchUnsafeAsync(String, Object, ArgDictionary, ArgDictionary, CancellationToken, LogActivity) to perform an HTTP without ensuring a non-error HTTP status code.

This class can also handle retrying operations when transient errors are detected. Customize SafeRetryPolicy and/or UnsafeRetryPolicy by setting a IRetryPolicy implementation such as LinearRetryPolicy or ExponentialRetryPolicy.

Note Note
This class initializes SafeRetryPolicy to a reasonable ExponentialRetryPolicy by default and UnsafeRetryPolicy to NoRetryPolicy. You can override the default retry policy for specific requests using the methods that take an IRetryPolicy as their first parameter.
Note Note

The JsonClientPayload class can be used to customize both the Content-Type header and the actual payload uploaded with POST and PUT requests. This can be used for those special REST APIs that don't accept JSON payloads.

All you need to do is construct a JsonClientPayload instance, specifying the value to be used as the Content-Type header and the payload data as text or a byte array and then pass this as the document parameter to the methods that upload content. The methods will recognize this special type and just send the specified data rather than attempting to serailize the document to JSON.

See Also