Building RESTful application using SQL Azure, WCF, ADO.NET Data Service & Telerik OpenAccess WCF Wizard




PUT vs POST in RESTful Web Service

Let us use a bookmark service as an example.



We can use PUT to create new user accounts because the client is the one picking the username that forms the new resource’s URI. If the client is successful, the service will return a 201 (“Created”) response. If the client attempts to use an existing username, the service will return a 401 (“Unauthorized”) response. When issuing the PUT request to create a user account, the client will provide a user account representation in the HTTP request body containing the user’s information.

For individual bookmark resources, we’ll support GET, POST, PUT, and DELETE requests. If a particular bookmark is marked as private, only the owner can retrieve it, but if it’s public, anyone can retrieve it. When a user creates a new bookmark, the service is responsible for assigning it a unique bookmark Id. Hence, the client won’t know the Id to use in the URI ahead of time. So, instead of using a PUT request, we’ll have users POST bookmarks to the user’s bookmark collection resource.  The handler for the POST request will create the new bookmark, assign it an Id, and return a 201 (“Created”) to the client, specifying the URI of the new bookmark resource in the Location header.

This explains when to use POST or PUT for creating new resources. The answer ultimately lies in who is responsible for determining the new resource’s URI. If the client is in charge, the client can use PUT to the new URI (like we did for user accounts) and the service can return a response code of 201 (“Created”). However, if the service is in charge of generating the new URI, the client should POST the new resource to a factory URI like we’ve done for bookmarks. Then, the service can return a response code of 201 (“Created”) along with the URI of the new resource in the response “Location” header.

Once clients know the bookmark ID’s, they can issue PUT and DELETE requests to individual bookmark URIs to update and delete bookmarks.

ADO.NET Data Services


ADO.NET Data Services Developer Center

ADO.NET Data Services Framework

10 mins Screencasts:

Using ADO.NET Data Services

Expose and Consume Data in a Web Services World MSDN Magazine Aug. 2008


Developing Applications Using Data Services
See how to use common libraries and tools when building applications using on premises and/or cloud services (Windows Azure services, SQL Data Services, etc.).

Programming Windows Azure Tables Using Data Services Client Libraries and Tools
Learn how to use the highly scalable, available and durable Windows Azure table storage service. This session presents a deep dive with demos (using ADO.NET Data Services clients & interaction conventions) showing in detail how to work with cloud storage.