Request and Response Formats

So far in this chapter, I have limited myself to one particular way of formulating a request to call a Flickr API method and the corresponding default format for the response. The Flickr API actually supports three different ways of packaging a request and five different formats for the response. In this section, I describe the choices you have with respect to request and response formats. Understanding these choices will help you make sense of APIs other than Flickr’s since you will face similar choices in working with them.

Regardless of the request or response format used, the Flickr API rests on HTTP. Hence, we need to remember that making a Flickr API call involves two steps, which is a reflection of the request and response pattern of the underlying HTTP protocol of the API:


Although web services are not necessarily tied to HTTP (for instance, SOAP can be bound to SMTP), HTTP is the only transport protocol supported for the Flickr API. However, the vast majority of web services used, especially for mashups, are made over HTTP. Hence, I don’t cover the use of transport protocols other than HTTP in this book.

Flickr supports three different request formats to call the methods of the API (REST, SOAP, and XML-­RPC):

There are current five different formats for Flickr responses: the three corresponding default response formats (REST, XML-­RPC, SOAP) and two specialized response formats (json and php_serial). In other words, a REST-­formatted request generates by default a REST-­formatted response. You can change the format for the response by using the format parameter.

The default behavior of tying the request and request format is typical for web APIs. With the exception of the REST-­to-JSON pairing, which we will return to in our discussion of Ajax programming in Chapter 8, the ability to decouple the request format from the response format is unusual. For instance, with the Flickr API, you issue a SOAP-­formatted request that asks for a REST-­formatted response. I’m not aware of any standard SOAP libraries that can handle such a pairing.

You can see for yourself these five formats in action through a simple REST-­formatted request:{api-ky}&format={format}

where format = rest, xmlrpc, soap, json, php_serial, or blank (for the default response format).