Web Rest API: Post

I’ve made a rest API and a frontend page that can currently only request items from an XML file and display them on the fronted page (GET operation)

Next step is to make a form, submit the form with Ajax and POST it to the API.

Frontend ajax POST operation

$("#formCars").submit(function (event) { $.ajax({ type: "POST", url: "http://localhost:51555/api/cars/", data: JSON.stringify($('#formCars')), dataType: "JSON" }).done(function (data) { }).fail(function (data) { console.log("error" + data); }); }); 

REST API POST (Auto generated)

 public void Post([FromBody]string value) { System.Diagnostics.Debug.WriteLine("API POST"+value); } 

Now the question is: The rest API function isn’t correct since it looks for a string value input, how do I change it so i can print out the posted form from the frontend?

submitted by /u/fig966
[link] [comments]

Leave a Reply