Im just starting to learn C# and building a service for a simple project. I am using Hasura as my API (GraphQL) and sending a Hasura action (POST webhook) to my C# app. It works by when the action mutation happens it sends the POST request. The issue im having is that the format of the request has a complex body.
The app works fine with just using Postman as the response is simple. The response for the Hasura is below.
request_query: 'mutation Mutation {\n' +
' validateName(card: "ADSADSA", email: "ADSADSA", name: "DASDADAS") {\n' +
' card\n' +
' name\n' +
' email\n' +
' }\n' +
'}\n' +
'\n' +
'query MyQuery {\n' +
' users {\n' +
' card\n' +
' email\n' +
' id\n' +
' name\n' +
' }\n' +
'}\n',
session_variables: { 'x-hasura-role': 'admin' },
input: { card: 'ADSADSA', email: 'ADSADSA', name: 'DASDADAS' },
action: { name: 'validateName' }
}
This is my current C# code.
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseHttpLogging();
app.MapPost("/validateName", async (User user) => {
Console.WriteLine(user.name);
var validateUser = new User();
validateUser.name = user.name?.ToLower();
validateUser.email = user.email?.ToLower();
validateUser.card = user.card?.ToLower();
return Results.Json(validateUser);
});
app.Run();
class User
{
public string? name { get; set; }
public string? email { get; set; }
public string? card { get; set; }
}
Firstly I would like to know how do I see the response in C#. Secondly how would i access the input of the body as this is where the key data I need.
Thanks.