Steps to Consume Web API in MVC.
Step1: Install HTTP Client library from NuGet.
What is HttpClient?
HttpClient is base class which is responsible to send HTTP request and receive HTTP response resources i.e from REST services.
Step2:Install WebAPI.Client library from NuGet
Step3: Add Model and Controller class.
Step4:
Our hosted Web API REST Service includes these two methods, as given below.
GetAllEmployees (GET )
GetEmployeeById (POST ) which takes id as input parameter
We are going to call GetAllEmployees method which returns the all employee details ,The hosted web api REST service base URL is http://192.168.95.1:5555/ and to call GetAllEmployees from hosted web API REST service, The URL should be Base url+api+apicontroller name +web api method name as following,
http://192.168.95.1:5555/api/Employee/GetAllEmployees
In the preceding url
http://localhost:56290 Is the base address of web API service, It can be different as per your server.
api It is the used to differentiate between Web API controller and MVC controller request .
Employee This is the Web API controller name.
GetAllEmployees This is the Web API method which returns the all employee list.
No comments:
Post a Comment