Skip to content
Discussion options

You must be logged in to vote

Use the non-generic IApiResponse as the return type. It is public and gives you status code, headers, success flags and error without forcing a content type.

[Post("/foo")]
Task<IApiResponse> Foo(RequestBody request, CancellationToken cancellationToken);

Then:

using var response = await api.Foo(request, ct);
if (response.IsSuccessStatusCode) { ... }
var code = response.StatusCode;

Notes:

  • IApiResponse (no type parameter) is the public, content-less response wrapper. It is verified as a supported return type (see ResponseTests.cs which uses Task<IApiResponse> and ValueTask<IApiResponse>).
  • Dispose it (or use using) since it owns the underlying response.
  • This avoids the ApiResponse<string> w…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants