using System.Text.Json;
using System.Text.Json.Serialization;
using Elsa.Workflows.Core.Serialization;
using FastEndpoints;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Extensions;
///
/// Provides extension methods to add the FastEndpoints middleware configured for use with Elsa API endpoints.
///
public static class WebApplicationExtensions
{
///
/// Register the FastEndpoints middleware configured for use with with Elsa API endpoints.
///
///
/// The route prefix to apply to Elsa API endpoints.
/// E.g. "elsa/api" will expose endpoints like this: "/elsa/api/workflow-definitions"
public static IApplicationBuilder UseWorkflowsApi(this IApplicationBuilder app, string routePrefix = "elsa/api") =>
app.UseFastEndpoints(config =>
{
config.Endpoints.RoutePrefix = routePrefix;
config.Serializer.RequestDeserializer = DeserializeRequestAsync;
config.Serializer.ResponseSerializer = SerializeRequestAsync;
});
private static ValueTask