0

I would like to make a Json Post Request to my MVC .NET application api beeing: http://localhost:39622/api/holiday

The Json file should represent the following class:

public class Holiday
{
    public string ldapName { get; set; }
    public DateTime date {get; set;}
}    

I have already initialized an instance of my model class within the "postHoliday" method and converted it to a JSON file.

    public void postHoliday()
    {
        Holiday holiday1 = new Holiday();
        holiday1.ldapName = "dkassube";
        holiday1.date = new DateTime(2016, 08, 01);
        string output = JsonConvert.SerializeObject(holiday1);
        WebRequest request = WebRequest.Create("localhost:39622/api/holiday");
        request.Method = "POST";

        // What to do here?
    }

I´m not really sure on how to send the JSON to my API controller and how I can handle the request when it arrives. When the API controller receives the JSON i want to convert it back to an instance of Holiday.

public class HolidayController : ApiController
{
    public Holiday handleIncomingHoliday()
    {
        Holiday incomingHoliday = new Holiday();

        // What to do here?

        return incomingHoliday;
    }
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120

0 Answers0