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...

4 comments:

mokeefe said...

Did you follow through with this approach? I'm thinking about doing something very similar but with JSON as the default.

Matthew Foemmel said...

No, I switched jobs recently and unfortunately didn't get around to implementing the protobuf thing at my old company before I left.

Sam said...

It was pretty straight-forward with JAX-RS:

http://www.javarants.com/2008/12/27/using-jax-rs-with-protocol-buffers-for-high-performance-rest-apis/

Sam

Parvin Jadon said...

Change is a phase of life that cannot be avoided or altered, but we can learn to live with them.
http://goatripsindia.com/goa-family-holiday-package