MVC4 Web API that Supports CRUD Operations Part 1

MCV4 have new feature is WEB API. CRUD stands for "Create, Read, Update, and Delete," which are the four basic database operations. Many HTTP services also model CRUD operations through REST or REST-like APIs.

Action

HTTP method

Relative URI

Get a list of allproducts

GET

/api/customer

Get a product by ID

GET

/api/customer/id

Get a product bycategory

GET

/api/customer?category=category

Create a new product

POST

/api/customer

Update a product

PUT

/api/customer/id

Delete a product

DELETE

/api/customer/id

The four main HTTP methods (GET, PUT, POST, and DELTETE) can be mapped to CRUD operations as follows:

  1. GET retrieves the representation of the resource at a specified URI. GET should have no side effects on the server.

  2. PUT updates a resource at a specified URI. PUT can also be used to create a new resource at a specified URI, if the server allows clients to specify new URIs. For this tutorial, the API will not support creation through PUT.

  3. POST creates a new resource. The server assigns the URI for the new object and returns this URI as part of the response message.

  4. DELETE deletes a resource at a specified URI.

Ebook Download
View all
Learn
View all