Book Review: RESTful Web Services by Samisa Abeysinghe
Two of my particular technology interests are Internet technologies and software development and I have recently been reading a book called “RESTful PHP Web Services” by Samisa Abeysinghe and published by Packt Publishing.
Having written about Web 2.0 throughout the year and looking at the state of Internet developments one particular area that is driving software development and integration is developers and web service providers opening up their API (Application Programming Interface) for others to access (or consume as you will learn in this book).
As HTTP is a stateless technology ways of trying to maintain some state between sessions is extremely useful. REST – or Representational State Transfer is a mechanism for allowing transfer of information between systems using familiar protocols. REST provides a common mechanism for information sharing and reuse and leads to the popularity of data remixability as it allows access to resources using the familiar URI (Uniform Resource Indicator). As you will discover in the book a server hosts resources and clients consume resources.
At 203 pages, there are 7 chapters with two appendices to get through and the writing feels very well paced with useful examples only a page turn away. The book starts out with a short background into REST then eases in to a simple example of obtaining a weather forecast from Yahoo and an example of how to process the resulting XML file. This is a followed up with an example of using the Flickr test echo API using a GET request before summarising six of the most popular PHP based REST frameworks.
Chapter 2 moves into a detailed outline and explanation of the PHP CURL API including the four steps of initialisation, option setting, execution and closing of a request. This is supported with examples using both SimpleXML and DOM for building up an XML message before handing over to HTTP for processing. The chapter closes with an insightful and practical example of accessing the Flickr API to produce an image search facility.
Chapter 3 covers further examples of consuming resources using a number of API including BBC News Feeds, Yahoo Search and Maps, and Earthquakes feed before going on to show how to consume and combine a number of web service resources to produce something new – in this instance overlaying information from the Earthquakes feed onto appropriate Yahoo Maps. It is not often I see examples showing how to combine the results of two web services so this example is quite enlightening.
Chapters 4 and 5 talk about services and clients respectively with Chapter 4 focusing on resource-oriented services and Chapter 5 focusing on resource-oriented clients. A simplified library system is used over the course of these two chapters to illustrate how particular functions work together.
Chapter 4 starts out with design. All software development should start out with a carefully considered design and RESTful services are no different, from describing what you aim to achieve through scoping the boundaries of what you are doing. The creation of the back-end database follows then consideration of the design of the URI pattern. As a resource is identified by its ID and the URI is essentially the ID the section dealing with URI pattern design is particularly worth paying close attention to.
Chapter 5 uses the previously described library service to show how to create a client application to consume the service. An important point is made in Chapter 5 explaining how the creation of any web service client depends on a clear understanding of the semantics of the service. Clear and detailed documentation is essential when creating a web service for clients to consume. The key elements of RESTful services and good code examples are contained within Chapters 4 and 5 so it is worth reading through these several times to understand the information being processed and how it relates.
Chapter 6 is dedicated to the implementation of the Zend framework which is a component library that helps with building PHP applications, and in particular the examples show how it can be used to build REST style services. The implementation of the simple library systems with the management of books and members is used again to demonstrate particular features of Zend.
Chapter 7 talks about how to debug REST web services. Utilising other web services where the inner workings are not exposed can make debugging tricky so an analysis of various techniques and considerations are discussed starting out with message tracing using a message capture tool with particular emphasis placed on TCPMon – I found the section on using TCPMon to debug common XML errors particularly useful. The chapter closes with a discussion on best practices to avoid common mistakes.
Appendix A gives a detailed overview of the WSO2 Web Service Framework for PHP whilst Appendix B includes a well thought out and ready built client class for building REST applications.
If you develop using PHP and have a keen interest in web services this book is well worth a read and the included examples clearly demonstrate how API implementations can benefit from RESTful web services. Particular API examples include Flickr, BBC News Feeds, Yahoo Maps and Yahoo Web Search. This 203 page book is available in both printed and eBook form for easier reading on the move.
You can read more about this book on the Packt website at http://www.packtpub.com/restful-php-web-services/
- £24.99
Submit a Comment