I am new to C#, JSON and web programming in general, so please correct me if I show signs of misunderstanding on certain concepts.
On ASP.NET Core 6, I want to use MapPost() to take a JSON string without having to deserialize it. I have previously made a class and successfully deserialized inputs, but now I want to try plain string. This is how part of my Web API's Program.cs looks like:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
Dictionary<string, string> mydictionary = new();
app.MapPost("/add_data/{queryKey}", (string queryKey, string jsonstring) =>
{
mydictionary.Add(queryKey, jsonstring);
return jsonstring;
});
An example of cURL API testing:
curl -X POST 'https://localhost:5001/add_data/my_first_entry' -d '{"name":"Sebastian", "age":35, "car":"Renault"}' -H 'Content-Type: application/json'
expected response:
'{"name":"Sebastian", "age":35, "car":"Renault"}'
Is it possible?
