Beispiel #1
0
        public static async Task HandleGetRequest(HttpContext context)
        {
            var result = await CompositionHandler.HandleGetRequest(context);

            if (result.StatusCode == StatusCodes.Status200OK)
            {
                string json = JsonConvert.SerializeObject(result.ViewModel, GetSettings(context));
                context.Response.ContentType = "application/json; charset=utf-8";
                await context.Response.WriteAsync(json);
            }
            else
            {
                context.Response.StatusCode = result.StatusCode;
            }
        }
        public static async Task HandleGetRequest(HttpContext context)
        {
            var result = await CompositionHandler.HandleGetRequest(context);

            if (result.StatusCode == StatusCodes.Status200OK)
            {
                // For the purposes of the demo, we're not respecting the HTTP Accept header and assuming that a JSON response is OK.
                context.Response.ContentType = "application/json; charset=utf-8";
                string json = JsonConvert.SerializeObject(result.ViewModel, GetSettings(context));
                await context.Response.WriteAsync(json);
            }
            else
            {
                context.Response.StatusCode = result.StatusCode;
            }
        }
        static async Task HandleRequest(HttpContext context)
        {
            var requestId = context.Request.Headers.GetComposedRequestIdHeaderOr(() => Guid.NewGuid().ToString());

            var(viewModel, statusCode) = await CompositionHandler.HandleRequest(requestId, context);

            context.Response.Headers.AddComposedRequestIdHeader(requestId);

            if (statusCode == StatusCodes.Status200OK)
            {
                string json = JsonConvert.SerializeObject(viewModel, GetSettings(context));
                context.Response.ContentType = "application/json; charset=utf-8";
                await context.Response.WriteAsync(json);
            }
            else
            {
                context.Response.StatusCode = statusCode;
            }
        }
Beispiel #4
0
        static async Task HandleRequest(HttpContext context)
        {
            var requestId = context.Request.Headers.ContainsKey("request-id")
                ? context.Request.Headers["request-id"].Single()
                : Guid.NewGuid().ToString();

            var result = await CompositionHandler.HandleRequest(requestId, context);

            context.Response.Headers.Add("request-id", requestId);

            if (result.StatusCode == StatusCodes.Status200OK)
            {
                string json = JsonConvert.SerializeObject(result.ViewModel, GetSettings(context));
                context.Response.ContentType = "application/json; charset=utf-8";
                await context.Response.WriteAsync(json);
            }
            else
            {
                context.Response.StatusCode = result.StatusCode;
            }
        }