Coming from NodeJS, a simple example to listen to a POST request on an endpoint would be
var express = require("express");
var myParser = require("body-parser");
var app = express();
app.use(myParser.urlencoded({extended : true}));
app.post("/myendpoint", function(request, response) {
console.log(request.body);
});
app.listen(8080);
I'm trying to do the same in a Blazor server app. I created a class that is as it appears below
using System;
using Microsoft.AspNetCore.Mvc;
namespace MyApp.Controllers
{
[ApiController]
[Route("api/myendpoints")]
public class MyEndpointController
{
[HttpPost]
public void MyEndpoint(string inputJSON)
{
Console.WriteLine(inputJSON);
}
}
}
When I do a POST request to https://localhost:5001/api/myendpoints/MyEndpoint with the following JSON in the body
{
"postcontent": "Lorem ipsum..."
}
I get 400 Bad Request. The request cannot be fulfilled due to bad syntax. This response means that the server could not understand the request due to invalid syntax.
How would one make the app listen to the end point? Is the class MyEndpointController supposed to be passed somewhere on Startup.cs?