Call CRUD(GET, POST, PUT, DELETE) API using HttpClient in c#
Here We will see how we can call all CRUD methods (GET, PUT, POST, DELETE) with the help of HttpClient in c#. 1. Call POST API :- string url = "http://localhost:26404/api/POSTAPI"; HttpClient httpClient = new HttpClient(); HttpResponseMessage APIResponse = new HttpResponseMessage(); var obj = new { name = "Amit", age = 26, subject = "c#" }; var objJson = JsonConvert.SerializeObject(obj); var stringContent = new StringContent(objJson, UnicodeEncoding.UTF8, "application/json"); APIResponse = httpClient.PostAsync(url, stringContent).GetAwaiter().GetResult(); var resultJson = APIResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult(); 2. Call GET API :- string url = "http://localhost:26404/api/GETAPI"; HttpClient httpClient = new HttpClient(); HttpResponseMessage APIResponse = new HttpResponseMessage(); APIResponse = httpClient.GetAsync(url).GetAwaiter().GetResult(); var resultJson = APIResponse.Content.ReadA...