Saturday, July 19, 2008

RESTful Protocol Buffers

I'm considering adding support for Protocol Buffers to the RESTful application that I'm currently working on, and was wondering what people thought.

I'm aware of all the arguments against using binary formats in REST APIs - but we deal with some pretty big sets of data on our project, and the speed and compactness of Protocol Buffers compared to XML/JSON is just too tempting. So here's how I'm thinking we might implement things:


  • XML will remain the default representation for all resources.

  • If the client includes the application/x-protobuf MIME type in their Accept header, the server will return a Protocol Buffer instead (and set the Content-Type to application/x-protobuf).

  • When a Protocol Buffer is returned, the HTTP response will also include an X-Protobuf-Schema header containing the URI for the .proto schema file.

Is anyone else doing something similar? It would probably make sense to coordinate on MIME types, etc...