On a previous post I outlined a procedure for implementing ReSTful Web Services. In this post I will expand that outline with the design/implementation of a Web Api for The Smart Shopping List.
Figure 1 shows a class diagram of the simple domain model for The Smart Shopping List.
Figure 1. The Smart Shopping List domain model
As you can see we have a Shopper that could have zero to many Stores and also zero to many Shopping Lists.
Each Store could have zero to many Product Categories and also zero to many Products.
Each Shopping List could have zero to many Products along with some other information.
Figure 2 shows a class diagram of the logical resources that will represent our Web Api.
Figure 2.The Smart Shopping List Resource Model
We have one entry point logical resource named Smart Shopping List, that advertises the Store & the Shopping List logical resources for each Shopper.
The Store logical resource contains two logical sub-resources Product Category & Product and the Shopping List logical resource has one Detail logical sub-resource.
Those logical resources and sub-resources are named by their Uris as depicted in Table 1.
Table 1. Logical Resources Uris
Each logical resource also implement a subset of the uniform interface as Table 2 shows.
If success, return 200 and a list representation. If not, 400.
Table 2. Logical Resource Uniform Interface subset
Figure 3 shows that each logical resource has two representations one for a single resource and another for its collection along with its status.
Figure 3. The Smart Shopping List Resource Representation Model
Also each resource representation contains links that advertises the logical resource status.
For the implementation I have used preview 4 of the WCF Web Api and I will be adding this code later this week (if everything goes smoothly ) to The Smart Shopping List Source Code. You also will be able to "test drive" The Smart Shopping List at https://webapi.smartshoppinglist.net but you have to create a Smart Shopping List account and also use the following headers with your client:
Accept: application/vnd.cyberbizsoft.ssl+xml
Authorization: Basic Your-User-ID:Your-Password (Base64 encoded)
When using POST, PUT & DELETE you must also add:
Content-Type: application/vnd.cyberbizsoft.ssl+xml
Just point your client to https://webapi.smartshoppinglist.net and follow the protocol.
Figure 4. Sample POSTing session using Fiddler.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.