I am very new to creating and consuming REST web services in C#. I have programmed the data I want to send over to REST end point. I am not sure if I am doing everything correctly. Like I mentioned previously, this is the first time I am writing a RESTful PUT request.
I have created a class and created a PUT request. I want to see my JSON result. It shows no content
. Functions are returning correct results for me.
How can I see my JSON result?
sb
is object of type Student
and when I am sending the request to the URL, it returns a 204
status and fails to update the record. I am trying to understand what is incorrect in this code:
class Student
{
public string Name{ get; set; }
public string Email{ get; set; }
public int Marks{ get; set; }
public List<int> Skills{ get; set; }
}
public static void SendDataSomewhere(List<Student> studentsList)
{
using (var client = new HttpClient())
{
Student sb = new Student
{
Name= "Test Name",
Email = "test@gmail.com",
Marks = HighestMarksFromList(studentsList),
Skills = InDemandSkills(studentsList),
};
client.BaseAddress = new Uri("http://testingApi.net/");
var response = client.PutAsJsonAsync("test", sb).Result;
if (response.IsSuccessStatusCode)
{
Console.Write("Success");
}
else
Console.Write("Error");
}
}
Functions are returning correct results for me. var response
is returning a 204
status code.
How can I see my JSON result?