In this age where it can sometimes seem like every system is connected to every other system, dealing with data has become a major ingredient in building the web. Whether you will be delivering services or consuming them, the web service is a key part of all modern, public-facing applications, and this book is here to help you navigate your way along the road ahead. There are chapters covering the different styles of service, from RPC and SOAP to REST and showing how you can devise great solutions using these existing approaches, and showing examples of APIs in the wild. Whether you’re sharing data between two internal systems, using a service back-end for a mobile application, or just plain building an API so that users can access their data, this book has you covered with everything you need, from the technical sections on HTTP, JSON and XML to the “big picture” areas such as creating a robust service.
Why did we pick PHP for this book? Well, PHP has always taken on the mission to “solve the web problem”. Web services are very much part of that “problem” and PHP is ideally equipped to make your life easy both when consuming external services and when creating your own. As a language, it runs on very many platforms and is the technology behind more than half of the web, so you can be sure that it will be widely available, wherever you are. This book does not adopt any particular frameworks; instead it aims to give you the tools you will need to understand the topic as a whole and apply that knowledge to whichever frameworks, libraries or other wrappers you choose to use.
The book walks you through everything you need to know in three broad sections. We begin by covering HTTP and the theory that goes with it, including detailed chapters on the request/response cycle, HTTP verbs and headers, and cookies. There are also chapters on JSON and XML; when to choose which data format, and how to handle these from within PHP. The second section aims to give very practical advice on working with RPC and SOAP services, with RESTful services, and how to debug pretty much anything that works over HTTP using a variety of tools and techniques. In the final section, we look at some of the wider issues around designing top-quality services, choosing what kind of service will work for your application, and how to make it robust. There is a chapter dedicated to how errors can be handled and also giving advice on why and how to document your API. Whether you dip into the book as a reference for a specific project, or read it in order to find out more about this area of technology, there’s something here to help you and your project to be successful. Enjoy!