Exposing Data as REST-Style Resources
This sample demonstrates how data can be exposed as REST resources through a data service and also how the service can be invoked in REST style.
About the sample
This sample scenario is based on a database which stores information about the products of an enterprise. There are separate queries/resources written for specific tasks of the products. Resources are defined in order to access data through REST calls. The resources implemented in the service are listed below.Â
- Create Product - Use HTTP POST request to insert new products.Â
Resource Path : productÂ
Resource Method : POST
- Update Product - Use HTTP PUT request to update product infomation.Â
Resource Path : productÂ
Resource Method : PUT
- GET Product - Use HTTP GET request to retreive product infomation for a given product code.Â
Resource Path : product/{productCode}Â
Resource Method : GET
- Get All Products - Use HTTP GET request to get all the products.Â
Resource Path : productsÂ
Resource Method : GET - Delete Product - Use HTTP DELETE request to delete a given product from the database.Â
Resource Path : product/{productCode}Â
Resource Method : DELETE
See Data Services and Resources for details.
Building the sample
The sample data service ResourcesSample should be deployed using the instructions in Samples Setup.
Running the sample
The service can be invoked in REST-style via curl (http://curl.haxx.se). The following commands can be executed using the command line to invoke each of the resources.
Create Product
curl -X POST -d '<product><productCode>S10_100</productCode><productName>1969 Harley Davidson Ultimate Chopper</productName><productLine>Motorcycles</productLine><quantityInStock>7933</quantityInStock><buyPrice>48.81</buyPrice></product>' --header 'Content-Type: application/xml' http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/product
Update Product
curl -X PUT -d '<product><productCode>S10_100</productCode><productName>1969 Harley Davidson Ultimate Chopper</productName><productLine>Motorcycles</productLine><quantityInStock>8000</quantityInStock><buyPrice>48.81</buyPrice></product>' --header 'Content-Type: application/xml' http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/product
Â
GET Product
curl -X GET http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/product/S10_100
Â
Get All Products
curl -X GET http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/products
Â
Delete Product
curl -X DELETE http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/product/S10_100