As a followup to my previous post, I now turn to RESTful web services. I originally encountered the term when attending php|tropics in 2005, where George Schlossnaggle likened it to simple GET and POST requests. Since then, the architectural style — and developer understanding of the architectural style — has improved a bit, and a more solid definition can be made.
At its heart, REST simply dictates that a given resource have a unique address, and that you interact with that resource using HTTP verbs. The standard verbs utilized are:
- GET: retrieve a list of resources, or, if an identifier is present, view a single resource
- POST: create a new resource with the data provided in the POST
- PUT: update an existing resource as specified by an identifier, using the PUT data
- DELETE: delete an existing resource as specified by an identifier
Creating a RESTful Web service is not simply about serving read-only content through HTTP
GET requests. It’s about using the full range of HTTP’s constrained interface to allow clients to consume or create resources within your service. Take a look at CouchDB, for example. Its initial releases look very promising, and the server accepts
DELETE requests to manipulate resources in the system. I can’t wait until the project implements authentication and authorization features; then, it will look much more attractive for real-world use.
But I digress… Continue reading
Web service designers have tried for some time now to correlate CRUD (Create, Retrieve, Update and Delete) semantics with the Representational State Transfer (REST) verbs defined by the HTTP specification–GET, PUT, POST, DELETE, HEAD, etc.
So often, developers will try to correlate these two concepts–CRUD and REST–using a one-to-one mapping of verbs from the two spaces, like this:
- Create = PUT
- Retrieve = GET
- Update = POST
- Delete = DELETE
“How to Create a REST Protocol” is an example of a very well-written article about REST, but which makes this faulty assumption. (In fairness to the author, he may well have merely “simplified REST for the masses”, as his article doesn’t specifically state that this mapping is the ONLY valid mapping. And indeed, he makes the statement that the reader should not assume the mapping indicates a direct mapping to SQL operations.) Continue reading
If you’re using Zend MVC and attempting to store transactional data, below is a quick and easy way to handle exceptions while still allowing rollbacks.
The code will essentially ensure that your transaction safely fails if an exception is thrown (i.e. the dreaded Integrity constraint violation: 1062 Duplicate entry) and fall back on your error controller for handling the exception. You can then deal with these exceptions in any manner you see fit by utilising Zend_Log_Writer_Stream. Continue reading
If your knowledge of constructors ends with “the place where I put my object initialization code,” read on. While this is mostly what a constructor is, the way a developer crafts their class constructor greatly impacts the initial API of a particular class/object; which ultimately affects usability and extensibility. After all, the constructor is the first impression a particular class can make.
Constructors, in their current form, have been in PHP since 5.0.0. Previous to 5.0, PHP loosely followed the style similar to that of C++ where the name of the method matching the name of the class would act as the class constructor. PHP 5 brought us the __construct() “magic method” which greatly formalized the new object initialization routine. Continue reading
Recently the Zend Framework team has started to use the Kanban system of AgileZen to manage the ZF2 project. In order to communicate, in real time, all the development phases of Zend Framework 2, we built a dev board page, in the Zend Framework web site, that reads the content of the AgileZen board using the REST API of that service (see figure below). Continue reading
Since the initial release of LiveDocx last week, one of the most common questions that I keep receiving via e-mail is:
How can I convert DOC to PDF in PHP?
Although it was not the original intention of LiveDocx to offer such file format conversion, it is very possible. In this post, I would like to present a little class, which does exactly that. Continue reading