in Education by
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 Skills{ get; set; } } public static void SendDataSomewhere(List studentsList) { using (var client = new HttpClient()) { Student sb = new Student { Name= "Test Name", Email = "[email protected]", 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? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
In my opinion, others have already answered it via answers as well as comments. But since the question is still open, let me try to answer with some more details. Your assumption that you should be able to get a JSON result as part of PUT API response is not always correct, it depends on the implementation of the API. Here are different ways a PUT API can be implemented: PUT API giving the object in response: [HttpPut] public HttpResponseMessage Put(int id, Product product) { //save the Product object. return Request.CreateResponse(HttpStatusCode.OK, product); } In this implementation, the API gives the object in the response, this is what you are expecting. PUT API giving empty response: [HttpPut] public void Put(int id, Product product) { //save the Product object. } In this implementation, API returns nothing in response. Based on your explanation, the API you are calling is following the second way. You can verify this if you have access to the API code. So, if your only problem is to know whether the API is not working or not, execute your code to do a PUT and then do a GET on the same object to verify if the update has been successful. Hope this helps!

Related questions

0 votes
    I would like to integrate SalesForce information into a .net MVC application. The samples on SalesForce website are ... .NET Thanks. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    How to reverse a string in c# console application?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    I've try to do the following instruction of this document : LINK I used SAS authentication and added this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I want to update order status to complete using webapi here is my testing code : $data = array ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    This is a cURL function that can send or retrieve data. It should work with any PHP app that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to configure SSL for Kafka Connect REST API (2.11-2.1.0). The problem I tried two ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Quandl API for Python wraps the ________ REST API to return Pandas DataFrames with time series indexes. (a) ... and answers pdf, Data Science interview questions for beginners...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    I have following Kubernetes REST API request GET https://theserver/api/v1/pods?includeUninitialized=true and included ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I want to create a request from my application. (iOS and Android - Coded with Xamarin). Explaination: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to fetch some data from the REST API of HP Alm. It works pretty well with a small ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    ALL I am confused about the date field returned by microsoft academic rest api: JSON Example: { " ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to execute a SOQL query using Salesforce REST API which will return 2,749 results. However, it seems ... the REST API. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is REST API in Informatica Cloud? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is Rest API? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why the REST API is popular? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
...