Asynchronous APIs: robust APIs in the post-REST world
REST, the king for inter-service APIS is not longer enough. In this talk I go over the design limitations of RESTful APIS and the alternatives to build production-ready APIS.
Presented at APIDAY MADRID 2017
transfer, technique for interoperability ◦ Client-server ◦ Cacheability ◦ Stateless ◦ Hypermedia as the engine of application state (HATEOAS) • RESTful -> Architecture style virtually always on top of HTTP protocol ◦ Use HTTP verbs (request methods) to provide meaning to the request itself ◦ Use HTTP response codes to provide meaning to the response itself
no “official” standard. REST is an architecture style, not a protocol • Little agreement on what HTTP error codes really mean • The REST vocabulary is not fully supported everywhere • The REST vocabulary is not rich enough for APIs • HTTP is NOT extensible!
code is not resource oriented • HTTP is hard ◦ GET and POST only syndrome ◦ 200 OK only syndrome • Request/Response information in many places • RESTful APIs are hard to debug
coupled to HTTP ◦ But we are sending JSON payloads... • Only one type of communication: client-server request-response ◦ No publish/subscribe, notification, etc. • HATEOAS constraint is hard to implement ◦ But provides little benefits!
Protocol-agnostic, so you can use it for APIs that work over MQTT, AMQP, WebSockets, STOMP, etc. • Heavily inspired on OpenAPI. Designed to maintain as much compatibility as possible with it. • Who -> Hitch, an API support platform for API providers • Why -> To be able to provide their services to message-driven APIs
we only need the server URL • New concept, topics ◦ Basically the same of HTTP URIs but protocol-agnostic ◦ Namespace for routing in MQ protocols -> routing key, destination, etc. ◦ Allows to define public and/or subscribe • New concept, messages ◦ A piece of information two or more programs exchange ◦ Describes the payload of the message in both requests and responses+ • New attribute scheme, servers must declare their protocol • Simplified Components Object, only messages, security and schemas
community -> ~50 GitHub stars • No big (public) project yet • Only one API platform supports it -> Hitch • Tooling -> documentation generator, Node code generator, online editor WIP • Strongly based on OpenAPI -> not reinventing the wheel (too much) • Very specific to MQ protocols but has an extension system
out there for Web APIs • Message-driven APIs are being used successfully in other areas • Why not use an unified architecture for all cases? • OpenAPI for message-driven APIs -> AsyncAPI • Not a drop-in replacement! More like an extension • AsyncAPI is in early stages but is a good starting point • The best technology is not the coolest one is the one that solves the problem
b. https://jeffknupp.com/blog/2014/06/03/why-i-hate-hateoas/ c. https://vimeo.com/20781278 d. http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven 2. JSON-pure APIs a. https://mmikowski.github.io/the_lie/ b. https://mmikowski.github.io/json-pure/ c. http://jsonapi.org/ 3. Query-efficient APIs a. http://graphql.org/ b. https://netflix.github.io/falcor/ 4. Machine-readable documentation for APIs a. https://www.asyncapi.com/ b. https://www.openapis.org/ 5. Interprocess communication a. https://www.nginx.com/blog/building-microservices-inter-process-communication/