IDownstreamApi.CallApiForUserAsync Method

Definition

Overloads

CallApiForUserAsync(String, Action<DownstreamApiOptions>, ClaimsPrincipal, HttpContent, CancellationToken)

Calls the downstream API on behalf of the user, based on a description of the downstream API in the configuration (service name), overridatable programmatically. This is a lower level API. There are other APIs for specific Http methods.

CallApiForUserAsync<TInput,TOutput>(String, TInput, Action<DownstreamApiOptions>, ClaimsPrincipal, CancellationToken)

Calls a downstream API consuming JSON with some data and returns data.

CallApiForUserAsync<TOutput>(String, Action<DownstreamApiOptions>, ClaimsPrincipal, CancellationToken)

Call a web API endpoint with an HttpGet, and return strongly typed data.

CallApiForUserAsync(String, Action<DownstreamApiOptions>, ClaimsPrincipal, HttpContent, CancellationToken)

Calls the downstream API on behalf of the user, based on a description of the downstream API in the configuration (service name), overridatable programmatically. This is a lower level API. There are other APIs for specific Http methods.

public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> CallApiForUserAsync (string? serviceName, Action<Microsoft.Identity.Abstractions.DownstreamApiOptions>? downstreamApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Net.Http.HttpContent? content = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CallApiForUserAsync : string * Action<Microsoft.Identity.Abstractions.DownstreamApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Net.Http.HttpContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function CallApiForUserAsync (serviceName As String, Optional downstreamApiOptionsOverride As Action(Of DownstreamApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional content As HttpContent = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of HttpResponseMessage)

Parameters

serviceName
String

Name of the service describing the downstream web API. There can be several configuration named sections mapped to a DownstreamApiOptions, each for one downstream API. You can pass-in null, but in that case downstreamApiOptionsOverride needs to be set.

downstreamApiOptionsOverride
Action<DownstreamApiOptions>

(Optional) Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

(Optional) Claims representing a user. This is useful on platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HTTP request context.

content
HttpContent

Content to send to the API in the case where HttpMethod is HttpMethod.Patch, Post, Put.

cancellationToken
CancellationToken

Cancellation token.

Returns

An HttpResponseMessage that the application will process.

Applies to

CallApiForUserAsync<TInput,TOutput>(String, TInput, Action<DownstreamApiOptions>, ClaimsPrincipal, CancellationToken)

Calls a downstream API consuming JSON with some data and returns data.

public System.Threading.Tasks.Task<TOutput?> CallApiForUserAsync<TInput,TOutput> (string? serviceName, TInput input, Action<Microsoft.Identity.Abstractions.DownstreamApiOptions>? downstreamApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Threading.CancellationToken cancellationToken = default) where TOutput : class;
abstract member CallApiForUserAsync : string * 'Input * Action<Microsoft.Identity.Abstractions.DownstreamApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Output (requires 'Output : null)> (requires 'Output : null)
Public Function CallApiForUserAsync(Of TInput, TOutput) (serviceName As String, input As TInput, Optional downstreamApiOptionsOverride As Action(Of DownstreamApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TOutput)

Type Parameters

TInput

Input type.

TOutput

Output type.

Parameters

serviceName
String

Name of the service describing the downstream API. There can be several configuration named sections mapped to a DownstreamApiOptions, each for one downstream API. You can pass-in null, but in that case downstreamApiOptionsOverride needs to be set.

input
TInput

Input parameter to the downstream web API.

downstreamApiOptionsOverride
Action<DownstreamApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful in platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

cancellationToken
CancellationToken

Cancellation token.

Returns

Task<TOutput>

The value returned by the downstream web API.

Examples

A list method that returns an IEnumerable<MyItem>>.

public Task<IEnumerable<MyItem>> GetAsync()
{
 return _downstreamWebApi.CallWebApiForUserAsync<object, IEnumerable<MyItem>>(
        ServiceName,
        null,
        options =>
        {
          options.RelativePath = $"api/todolist";
        });
}

Example of editing.

public Task<MyItem> EditAsync(MyItem myItem)
{
  return _downstreamWebApi.CallWebApiForUserAsync<MyItem, MyItem>(
        ServiceName,
        nyItem,
        options =>
        {
           options.HttpMethod = HttpMethod.Patch;
           options.RelativePath = $"api/todolist/{myItem.Id}";
        });
}

Applies to

CallApiForUserAsync<TOutput>(String, Action<DownstreamApiOptions>, ClaimsPrincipal, CancellationToken)

Call a web API endpoint with an HttpGet, and return strongly typed data.

public System.Threading.Tasks.Task<TOutput?> CallApiForUserAsync<TOutput> (string serviceName, Action<Microsoft.Identity.Abstractions.DownstreamApiOptions>? downstreamApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Threading.CancellationToken cancellationToken = default) where TOutput : class;
abstract member CallApiForUserAsync : string * Action<Microsoft.Identity.Abstractions.DownstreamApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Output (requires 'Output : null)> (requires 'Output : null)
Public Function CallApiForUserAsync(Of TOutput As Class) (serviceName As String, Optional downstreamApiOptionsOverride As Action(Of DownstreamApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TOutput)

Type Parameters

TOutput

Output type.

Parameters

serviceName
String

Name of the service describing the downstream API. There can be several configuration named sections mapped to a DownstreamApiOptions, each for one downstream API. You can pass-in null, but in that case downstreamApiOptionsOverride needs to be set.

downstreamApiOptionsOverride
Action<DownstreamApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful in platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

cancellationToken
CancellationToken

Cancellation token.

Returns

Task<TOutput>

The value returned by the downstream web API.

Applies to