<PackageReference Include="Refit" Version="17.0.0" />

Refit.GeneratedRequestRunner

public static class GeneratedRequestRunner
Request body content creation for source-generated requests: JSON, JSON Lines, and URL-encoded forms.
public static void AddConfiguredRequestOptions(HttpRequestMessage request, RefitSettings settings, Type interfaceType)

Adds the configured request options/properties, along with the HTTP version and version policy, shared by every generated request.

public static void AddFormattedCollectionProperty(ref GeneratedQueryStringBuilder builder, RefitSettings settings, IEnumerable values, string key, CollectionFormat collectionFormat, bool preEncoded, ValueTuple<Type, IParameterAttributeProvider, Type> formatting)

Expands a query-object collection property through a customized IUrlParameterFormatter, reproducing the reflection request builder's two formatting passes.

public static void AddHeaderCollection(HttpRequestMessage request, IDictionary<string, string> headers, bool validateHeaders)

Adds a generated request header collection, replacing earlier values by key.

public static void AddRequestProperty<TValue>(HttpRequestMessage request, string key, TValue value)

Adds one generated request property or option value.

public static string BuildFormKey(RefitSettings settings, string clrName, string explicitName, string jsonName, string newtonsoftName, string xmlName, string prefixSegment)

Builds a form field key, choosing the compile-time name that matches the configured content serializer.

public static string BuildQueryKey(RefitSettings settings, string clrName, string explicitName, string prefixSegment)

Composes the query key for a property flattened out of a query object.

public static Uri BuildRelativeUri(HttpClient client, string relativePath, UrlResolutionMode urlResolution)

Builds the relative request URI for a generated request, joining the client base address with the method path.

public static Uri BuildRelativeUri(HttpClient client, string relativePath, UrlResolutionMode urlResolution, UriFormat queryUriFormat)

Builds the relative request URI, re-encoding the whole path and query with a [QueryUriFormat] mode.

public static string BuildRequestPath(string relativePathTemplate, bool allowUnmatchedParameter, ReadOnlySpan<ValueTuple<ValueTuple<int, int>, string>> uriParams)

Builds the request path for a generated request from a template.

public static string BuildRequestPath(string relativePathTemplate, bool allowUnmatchedParameter)

Validates a parameterless request path template, throwing for unmatched placeholders.

public static string BuildRequestPath(string relativePathTemplate, bool allowUnmatchedParameter, ReadOnlySpan<ValueTuple<ValueTuple<int, int>, string, bool>> uriParams)

Builds the request path for a generated request from a template, honoring per-value encoding opt-outs.

public static bool CanUnrollForm(object body)

Determines whether a form body can be serialized by the generated straight-line unrolled fast path.

public static HttpContent CompressBodyContent(HttpContent content, RefitSettings settings, RequestCompression compression, CompressionLevel level)

Applies the request body coding a body parameter or the settings asked for.

public static HttpContent CreateAsyncJsonLinesBodyContent<TElement>(RefitSettings settings, IAsyncEnumerable<TElement> body)

Serializes a generated JSON Lines body declared as an asynchronous sequence.

public static HttpContent CreateBodyContent<TBody>(RefitSettings settings, TBody body, BodySerializationMethod serializationMethod, bool streamBody)

Serializes a generated request body using Refit body rules.

public static HttpContent CreateJsonLinesBodyContent<TBody>(RefitSettings settings, TBody body)

Serializes a generated request body as JSON Lines (newline-delimited JSON).

public static HttpContent CreateStreamContent(Stream stream)

Wraps a caller-supplied stream in HTTP content that does not dispose it.

public static HttpContent CreateTypedJsonLinesBodyContent<TElement>(RefitSettings settings, IEnumerable<TElement> body)

Serializes a generated JSON Lines body declared as a synchronous sequence of a sealed or value element type.

public static HttpContent CreateUrlEncodedBodyContent<TBody>(RefitSettings settings, TBody body)

Serializes a generated URL-encoded request body using the declared body type.

public static HttpContent CreateUrlEncodedBodyContent<TBody>(RefitSettings settings, TBody body, FormField<TBody>[] fields)

Serializes a generated URL-encoded request body using source-generated field descriptors.

public static string FormatInvariant<T>(T value, string format) where T : IFormattable

Formats a value with the invariant culture, matching the default URL parameter formatter's rendering for IFormattable values without boxing or reflection.

public static string FormatUrlParameter(RefitSettings settings, object value, IParameterAttributeProvider attributeProvider, Type type)

Resolves the IUrlParameterFormatter for a value, consulting the per-type registry on the settings before falling back to the configured default, then formats the value with it.

public static string RequireAbsoluteUrl(object url)

Validates that a [Url] parameter value is an absolute URI, returning its string form as the base for a full-URL request that bypasses the client's base address. A String value is used as written; a Uri value contributes its OriginalString.

public static string RequireRelativeOrAbsoluteUrl(object url)

Validates an opt-in relative or absolute URL without escaping its path or query.

public static string RoundTripEscapePath(string value, RefitSettings settings, IParameterAttributeProvider attributeProvider, Type type)

Round-trips a catch-all {**param} path value: each /-separated section is formatted and escaped while the separators are preserved, matching the reflection request builder.

public static Task<T> SendAsync<T, TBody>(HttpClient client, HttpRequestMessage request, RefitSettings settings, bool isApiResponse, bool shouldDisposeResponse, bool bufferBody, CancellationToken cancellationToken)

Sends a generated request and deserializes or wraps its response.

public static IObservable<T> SendObservable<T, TBody>(HttpClient client, Func<HttpRequestMessage> requestFactory, RefitSettings settings, bool isApiResponse, bool shouldDisposeResponse, bool bufferBody, CancellationToken methodCancellationToken)

Sends a generated request as a cold IObservable<T>: each subscription rebuilds and sends the request, mirroring the reflection request builder.

public static Task SendVoidAsync(HttpClient client, HttpRequestMessage request, RefitSettings settings, bool bufferBody, CancellationToken cancellationToken)

Sends a generated request with no response body, throwing on HTTP errors.

public static HttpContent SerializeMultipartPart<T>(RefitSettings settings, T value, string fieldName)

Serializes a multipart part through the content serializer, wrapping a failure with the same descriptive argument exception the reflection request builder raises for an unserializable part.

public static void SetHeader(HttpRequestMessage request, string name, string value, bool validateHeaders)

Sets, replaces, or removes a generated request header.

public static void SetRequestTimeout(HttpRequestMessage request, int timeoutMilliseconds)

Stashes a method's [Timeout] value on the request for the send helpers to apply.

public static IAsyncEnumerable<T> StreamAsync<T>(HttpClient client, HttpRequestMessage request, RefitSettings settings, CancellationToken methodCancellationToken, CancellationToken cancellationToken = default)

Sends a generated request and streams the response as an IAsyncEnumerable<T>.

Determines whether the settings use the pristine default form-url-encoded parameter formatter.

public static bool UsesDefaultUrlParameterFormatting(RefitSettings settings)

Determines whether the settings use the pristine default URL parameter formatter, letting generated code format statically-known values inline without calling the formatter.

Determines whether the settings use the pristine default URL parameter key formatter, letting generated code use a compile-time constant query key instead of calling the formatter.