Table of Contents

Class ServiceHttpClient

Namespace
Shard.Network.Http
Assembly
Shard.Network.dll

Outbound HTTP client for backend services (Session/Account/OAuth/JWKS). The game server runs no HTTP listener: every HTTP touchpoint is an outbound call. Mirrors the Java ServiceHttpClientFactory + service-client plumbing: Bearer auth, JSON bodies, a 30s default timeout, and a HytaleServer/<version> user agent. Shard.Auth builds typed service calls on top of this.

JSON uses JsonTypeInfo<T> so it stays NativeAOT-safe.

public sealed class ServiceHttpClient : IDisposable
Inheritance
ServiceHttpClient
Implements
Inherited Members

Constructors

ServiceHttpClient(string, TimeSpan?, HttpMessageHandler?)

public ServiceHttpClient(string userAgent, TimeSpan? timeout = null, HttpMessageHandler? handler = null)

Parameters

userAgent string
timeout TimeSpan?
handler HttpMessageHandler

Methods

DeleteAsync(string, string?, CancellationToken)

public Task DeleteAsync(string url, string? bearer = null, CancellationToken ct = default)

Parameters

url string
bearer string
ct CancellationToken

Returns

Task

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetJsonAsync<TResponse>(string, JsonTypeInfo<TResponse>, string?, CancellationToken)

public Task<TResponse?> GetJsonAsync<TResponse>(string url, JsonTypeInfo<TResponse> responseInfo, string? bearer = null, CancellationToken ct = default)

Parameters

url string
responseInfo JsonTypeInfo<TResponse>
bearer string
ct CancellationToken

Returns

Task<TResponse>

Type Parameters

TResponse

PostFormAsync<TResponse>(string, IEnumerable<KeyValuePair<string, string>>, JsonTypeInfo<TResponse>, string?, CancellationToken)

POST a form-encoded body and read the JSON response. Does NOT throw on non-success status, since OAuth endpoints return JSON error bodies (e.g. authorization_pending) with 4xx.

public Task<TResponse?> PostFormAsync<TResponse>(string url, IEnumerable<KeyValuePair<string, string>> form, JsonTypeInfo<TResponse> responseInfo, string? bearer = null, CancellationToken ct = default)

Parameters

url string
form IEnumerable<KeyValuePair<string, string>>
responseInfo JsonTypeInfo<TResponse>
bearer string
ct CancellationToken

Returns

Task<TResponse>

Type Parameters

TResponse

PostJsonAsync<TRequest, TResponse>(string, TRequest, JsonTypeInfo<TRequest>, JsonTypeInfo<TResponse>, string?, CancellationToken)

public Task<TResponse?> PostJsonAsync<TRequest, TResponse>(string url, TRequest body, JsonTypeInfo<TRequest> requestInfo, JsonTypeInfo<TResponse> responseInfo, string? bearer = null, CancellationToken ct = default)

Parameters

url string
body TRequest
requestInfo JsonTypeInfo<TRequest>
responseInfo JsonTypeInfo<TResponse>
bearer string
ct CancellationToken

Returns

Task<TResponse>

Type Parameters

TRequest
TResponse