Meme Generation API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kynareth/src/Helpers/ResponseHelper.cs

34 lines
1.0 KiB

using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using Exsersewo.Common.Converters;
using Exsersewo.Common.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Kynareth.Helpers;
public static class ResponseHelper
{
private static readonly JsonSerializerOptions SerializerOptions = new()
{
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true,
Converters = { new LongToStringConverter() }
};
public static object Send(this HttpContext Context, EventResult result, HttpStatusCode status = HttpStatusCode.OK)
{
Context.Response.ContentType = "application/json";
Context.Response.StatusCode = (int)status;
return new JsonResult(result, SerializerOptions);
}
public static object SendStream<T>(this HttpContext Context, T stream, string contentType, HttpStatusCode status = HttpStatusCode.OK) where T : Stream
=> new StreamResult(stream)
{
ContentType = contentType,
StatusCode = (int)status
};
}