// this will build a mock ApiRequest/Response and record the logs/metrics of the underlying mvc middleware public static RequestDelegate WithAlteredAspNet(RequestDelegate aspnet, CloudwatchLogsSink cloudwatchLogs, CloudwatchMetricsSink cloudwatchMetrics) { return(async(httpContext) => { var request = httpContext.Request; var mvcRequest = new AlteredApiRequest { Path = request.Path, HttpMethod = request.Method, Headers = request.Headers, QueryStringParameters = QueryHelpers.ParseQuery(request.QueryString.Value) }; var pipeline = new AlteredPipeline <AlteredApiRequest, AlteredApiResponse>(async(_) => { await aspnet(httpContext); var mvcResponse = new AlteredApiResponse { StatusCode = httpContext.Response.StatusCode, Headers = httpContext.Response?.Headers }; return mvcResponse; }) .WithCloudwatchLogs(cloudwatchLogs, mvcRequest.Path) .WithCloudwatchMetrics(cloudwatchMetrics, mvcRequest.Path); var response = await pipeline.Execute(mvcRequest); }); }
public MySampleApiCallMvc(IMySampleApiCall mySampleApiCall, CloudwatchLogsSink logs, CloudwatchMetricsSink metrics) : base(mySampleApiCall .WithAlteredLogsApi() .WithCloudwatchMetrics(metrics, nameof(MySampleApiCallMvc)) .WithCloudwatchLogs(logs, nameof(MySampleApiCallMvc))) // this function could populate the Entity property of your request // by reading the EntityId property and calling cdom // that code would be written once, and work with code/lambda/api/exe/etc // as long as its request shape implements IEntity //.WithCdomEntity() { }