Most modern API's are built using JSON with request/response messaging over HTTP. Since ZeroMQ is over TCP, could JSON-based API's be built over ZeroMQ? If so, what would the advantages be? The use is
developers writing apps for clients/devices communicating with one or more webservers, and
webservers communicating with webservers.
Yes, json-based API could be built on top of ZeroMQ instead of HTTP. It would require REQ/REP sockets. However, it doesn't seem to be a good choice.
The main advantage of JSON+HTTP approach is portability. JSON+HTTP is supported out of the box by virtually any programming environment, ZeroMQ is not supported so widely (no support in browser JS for example). Also, ZeroMQ is not so painless in setup, so service consumers probably won't be happy with that choice.
On the other hand, the main advantage of ZeroMQ is performance: it's great if you need to push many megabytes (or probably gigabytes) of data per second. JSON encoding/decoding is really fast, but the size matters too for this kind of tasks. Any binary serialization framework seems to be a better choice, there are plenty: protobuf, thrift, BSON, kryo, avro, etc.
So, I'd continue to use JSON+HTTP for APIs of web services: modern HTTP server tools provide excellent performance and scalability. And ZeroMQ is a great choice for communication within a controlled environment because of its concurrency features and well-defined usage patterns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With