Exercise: Consuming a RESTful service
There is a simple RESTful service running on http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/
Example URIs
GET (read information)
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/1
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/1/title
POST (add information)
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books
Add a new book (data in the request body).
PUT (update information)
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/1
Update book with Id=1.
Data in the request body
DELETE (delete information)
- http://anbo-restserviceproviderbooks.azurewebsites.net/Service1.svc/books/1
Delete book with Id=1
Use a browser
With a browser you can easily use the HTTP method/verb GET on the URIs.
Use WireShark to object the requests and responses.
Use Postman
Postman is an application for Google Chrome. With Postman you can use all the HTTP methods/verbs: GET, PUT, PUT, DELETE, etc.
- Make sure you have Google Chrome
- Download Postman from the Chrome web store.
Postman documentation
- Use Postman to send GET, POST, PUT and DELETE requests to the service (the service might not support all the HTTP methods/verbs)
Please, do not destroy the data.
Only update and delete data that you created.
Clean up the objects you added.
Use WireShark to object the requests and responses.
Make your own client application
In Visual Studio create a simple Console Application.
The application should
- send request to the Book service.
- read the response
- if the response includes data, then create one or more objects from this data
Sending request and reading response can be done using the class HttpClient.
Maybe you want to add some extension method PutAsJsonAsync and PostAsJsonAsync: Nuget System.Net.Http.Formatting
Making objects can be done using JSON or XML de-serialization, see the plan. Nuget NewtonSoft.Json.
You will probably have to make a model/transport class Book with properties that match the properties of the Book service.
Use WireShark to observe the requests and responses.