Creating a Web Api that Supports CRUD

Based on :
http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations

GET – read
PUT – update (replaces the entire product) (U—>U)
POST – Add
DELETE – delete.
Create a new MVC 4 –> WEB API Project
image
Adding a Model
image
Adding A Repository (Repository Pattern)
In /Models, create a new Interface
(1) models –> Add –> New item
(2) Select [Interface] (IProductRepository)
image
In this interface, define the methods needed for Product.
image
Now, again in /Models, add a ProductRepository.cs that implements IProductRepository interface. And define the detail implementation.
A shortcut to implement all methods:
image
Detail implementation:
image
image
This complete the basic CRUD data repository – basically a data access layer. Now we’re creating a WebAPI that uses this repository to access data.
Add a ProductsController/Empty API Controller.
image
ProductsController: GET/POST/PUT/DELETE
image
image
09:13pm, 01/25/2013

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s