jgraichen / restify

Restify is a experimental, parallel and pipelined Hypermedia API client
GNU Lesser General Public License v3.0
8 stars 2 forks source link

Add a Msgpack processor #13

Closed franzliedke closed 6 years ago

franzliedke commented 6 years ago

This is intended to use as a drop-in replacement for JSON. The two encodings support the same datatypes, thus HTTP's content negotiation can be used to tell a server to deliver a Msgpack response (if it is capable to do so). Fully transparent to the API consumer, this can reduce the HTTP payload by 50 percent in some cases.

Example HTTP Request:

GET /path HTTP/1.1
Host: restify.de
Accept: application/msgpack, application/json

If the server supports msgpack, it will deliver that serialization; if it does not, it will fall back to JSON. Restify will be able to handle both.

Spec: https://msgpack.org/ Library: https://github.com/msgpack/msgpack-ruby

franzliedke commented 6 years ago

I did extract the duplicate code now; with the indifferent_access stuff in place it is important for the two to stay in sync.

franzliedke commented 6 years ago

Though maybe this code actually belongs in the Json transformer? :thinking:

franzliedke commented 6 years ago

Half-and-half, I think. Traversing the returned hash / array and wrapping it in Resource objects is generic - interpreting _url as links is probably JSON-specific.

franzliedke commented 6 years ago

@jgraichen Is there anything I can do to finish this up?

franzliedke commented 6 years ago

@jgraichen Could we merge this and release it as experimental, private API for now? That way, we could easily use it to figure out whether it positively impacts serialization times in a relevant way on our services...