public static void Main()
var responseError = Response<HelloWorld>.FromError("Survey not configured");
var responseNotFound = Response<HelloWorld>.FromNotFound("1");
Console.WriteLine("In case of 400 ---");
Console.WriteLine(JsonSerializer.Serialize(responseError, new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine("\n In case of 404 --- \n ");
Console.WriteLine(JsonSerializer.Serialize(responseNotFound, new JsonSerializerOptions { WriteIndented = true }));
public int StatusCode {get;set;}
public string Error { get; set; }
public static Response<T> FromError(string errorReason)
return new Response<T>{Error = typeof(T).Name + " has generated an error : " + errorReason + ".", StatusCode = 400};
public static Response<T> FromNotFound(string id)
return new Response<T>{Error = typeof(T).Name + " with ID : " + id + " is not found.", StatusCode = 404};
public string Hello { get; init; } = "Hello";
public string World { get; init; } = "World!";