nokia / restful

A powerful RESTful framework for Go.
BSD 3-Clause "New" or "Revised" License
17 stars 14 forks source link

MessagePack support #30

Closed Som-Som-CC closed 6 months ago

Som-Som-CC commented 2 years ago

MessagePack (a.k.a. msgpack) is a great data interchange format. It is often cited as binary JSON. Flexible like JSON, but more efficient. Not as snappy as Protocol Buffers/gRPC, but more flexible and still fast.

The aim of this enhancement:

Go standard JSON library uses "json" tagging. The msgpack package chosen must be able to use that tagging for smooth interworking.

sequenceDiagram
note over C: MessagePack discovery phase
C->>S: POST: CT:application/json, Accept:application/msgpack,application/json, body=JSON
S->>C: 201: CT=application/msgpack, body=msgpack
note over C: MessagePack is known to be supported
C->>S: PUT: CT:application/msgpack, Accept:application/msgpack,application/json, body=msgpack
S->>C: 200: CT=application/msgpack, body=msgpack
Som-Som-CC commented 10 months ago

https://github.com/vmihailenco/msgpack/ seems to be a nicely maintained msgpack implementation with SetCustomStructTag functions.

For large structs it seems to be twice as fast as encoding/json with half the number of allocations (though memory use on a par or even higher) and somewhat more dense binary data. That is what one would expect when reading msgpack specification.

Som-Som-CC commented 9 months ago

You may ask why MessagePack when there are more popular and snappier protocols. Such as Protobuf, used by gRPC, Connect RPC or Twirp.

There can be many reasons. For example, these are much more than versatile than a RESTful resource manipulation. Protobuf is not a drop-in replacement for JSON, hence its efficiency. And most importantly, these libs provide all the bells and whistles what this restful lib provides.

Som-Som-CC commented 6 months ago

Ongoing. See https://github.com/nokia/restful/pull/63