Thursday, April 25, 2019

.Net REST Web service using Visual Studio

Step 1:- Creat a new project
Image1Image2Image3
click on Create Button
Image4Image5Image6
Step 2:-
Now we will create the below classes for handling our GET, POST, PUT, and DELETE services from client
Right-click on the Models folder from the project explorer window and select Add=>Class
Image7Image8

Modify Employee Class as given below

Image9
Step3:-
We will have one class that will containt he original logic that will perform GET/POST/PUT/DELETE Operation
i.e.
GET:- To get all the information of the resource.
POST:- TO create the resource
PUT:- To Update the resource if present or cretae it if not present.
DELETE:- To delete the resource.
Image10
Step 4:-
Now lets develop the controller. This is the front facing class of server to client i.e. all the request are first diverted to this controler and depending on it further corresponding business logic class method is called.
We will first creat the GET Controller class. Right-click on the Controllers folder and select Add=>Controller. From the below window, select Web API 2 Controller — Empty
Image11Image12
Click Add button

Image13Image14Image15Image16
Hurrey !!! you are done with exposing your first REST service. Run the application and hit the url
Same way we need to create Controller for all the different operaiton i.e. PUT/POST/DELETE.
Note:- Please see the url
http://localhost:55486/api/employeeretrive
employteeretrive = EmployeeRetriveController

No comments: