{"id":221,"date":"2021-02-02T20:01:24","date_gmt":"2021-02-02T20:01:24","guid":{"rendered":"https:\/\/fde.cat\/?p=221"},"modified":"2021-02-02T20:01:25","modified_gmt":"2021-02-02T20:01:25","slug":"asyncapi-and-openapi-an-api-modeling-approach","status":"publish","type":"post","link":"https:\/\/fde.cat\/index.php\/2021\/02\/02\/asyncapi-and-openapi-an-api-modeling-approach\/","title":{"rendered":"AsyncAPI and OpenAPI: an API Modeling Approach"},"content":{"rendered":"<p><a href=\"https:\/\/www.asyncapi.com\/\">AsyncAPI<\/a> is gaining traction in the ecosystem of API tools. It solves an important problem: it provides a convenient way of describing the interface of event-driven systems independently of the underlying technology. With AsyncAPI, evented systems can be treated as any other API product: a productizable and reusable, self-describing building block encapsulating some set of data and capabilities. AsyncAPI also provides an essential component required to develop tooling taking advantage of a way of describing a standard interface for the asynchronous API in order to support the full development cycle of the evented\u00a0system.<\/p>\n<p>The downside of the rise of AsyncAPI is that it introduces yet another specification and industry standard in an already fragmented API landscape: <a href=\"https:\/\/github.com\/OAI\/OpenAPI-Specification\">OAS<\/a>, <a href=\"https:\/\/spec.graphql.org\/June2018\/\">GraphQL<\/a>, <a href=\"https:\/\/github.com\/grpc\/grpc\">gRPC<\/a>, <a href=\"https:\/\/docs.oasis-open.org\/odata\/odata\/v4.01\/odata-v4.01-part1-protocol.html\">OData<\/a>, <a href=\"https:\/\/github.com\/raml-org\/raml-spec\/blob\/master\/versions\/raml-10\/raml-10.md\">RAML<\/a> and now <a href=\"https:\/\/github.com\/asyncapi\/asyncapi\">AsyncAPI<\/a> all provide solutions to understand through metadata the interface of modern APIs and they do it with different degrees of overlap. This can sometimes lead to confusion about the relationship between all these technologies and when to use each of\u00a0them.<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1000\/1*dWQWFgrPNReK0u2Q8JYCIg.png?w=750&#038;ssl=1\" data-recalc-dims=\"1\"><\/figure>\n<p>At MuleSoft, we have long embraced a multi-spec, metadata-driven approach to API interfaces. We developed our open-source parsing and metadata framework, <a href=\"https:\/\/github.com\/aml-org\/amf\">AMF<\/a>, to support the API development lifecycle of our customers and their API supply chain, no matter what specific technologies they want to\u00a0use.<\/p>\n<p>Our approach is based on defining a formal model that captures the semantics of the different specification languages. We achieve that by mapping elements of the specification syntax to a well-defined taxonomy of concepts in a <a href=\"https:\/\/github.com\/aml-org\/amf-metadata\/blob\/develop\/vocabulary\/src\/main\/resources\/vocabularies\/api_contract.yaml\">modeling vocabulary<\/a>. Then, when we parse API definitions in the specification languages, we generate a graph of metadata where each node and edge is mapped to one of the concepts in the modeling vocabulary. We capture in a standard way the data model and semantics of the information provided by the API definition document.<\/p>\n<p>If two specs overlap in their meaning, we map them to the same common concepts. This allows us to identify the overlap between the different specification languages.<\/p>\n<p>In our framework, we use well-tested W3C standards (e.g. <a href=\"https:\/\/json-ld.org\/\">JSON-LD<\/a>, <a href=\"https:\/\/www.w3.org\/TR\/shacl\/\">SHACL<\/a>) that give us a solid foundation to build sophisticated tooling on top of the graph of metadata. The use of standards also gives us access to an array of battle-proven industry tools to work with the API\u2019s metadata, like <a href=\"https:\/\/aws.amazon.com\/neptune\/\">Amazon Neptune<\/a> for metadata\u00a0storage.<\/p>\n<p>So when we need to support a new type of spec, the first question we ask ourselves is, what are the semantics of this API specification language? In other words, what type of APIs is it trying to describe? Answering this question is not always easy. Industry-driven specification languages usually lack well-defined semantics and can be ambiguous. They usually provide some grammar and schema information about the syntax of the specification but just some informal textual description of the meaning of those elements. The task of understanding and formally capturing the underlying meaning of the spec is sometimes a confusing one.<\/p>\n<p>OpenAPI (OAS, before Swagger) is an interesting example. It has been described as a \u2018web API language\u2019 and many people think of OAS as a standard way of specifying \u2018RESTful\u2019 APIs.<\/p>\n<p>When we added support for OAS, we modeled it as a \u2018web RPC\u2019 language. What we mean by this is that OAS is not describing canonical REST APIs (resources, hypermedia, HATEOAS), although you can define conventions to store a REST model in OAS. Rather, it is describing a classic RPC mechanism that uses HTTP as the transport layer.<\/p>\n<p>At the core of our RPC model for OAS, there is a list of endpoints bound to HTTP URLs exposing operations bound to HTTP methods, expecting and returning HTTP encoded parameters and payloads.<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*D4KiVYJRQhfpVMJU\"><\/figure>\n<p>Additionally, JSON Schema is the usual way of describing the data structures being exchanged in the messages. We modeled these schemas using SHACL, the standard W3C language for data shapes, with some extensions<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*0j5VxLdQoeCRMYZ_\"><\/figure>\n<p>This web RPC model has allowed us to model other \u2018RESTful\u2019 specification languages like RAML using the same common underlying vocabulary.<\/p>\n<p>When we started looking at AsyncAPI, the same question came to mind: what are the actual semantics of AsyncAPI? What type of systems is AsyncAPI trying to describe?<\/p>\n<p>AsyncAPI introduces a key concept in the way it makes it possible to define evented systems. It defines a conceptual boundary around the system, delimiting and encapsulating the internal implementation and the external set of clients consuming and producing information.<\/p>\n<p>These clients interact through a well-defined interface accessible through multiple channels, exposing two asynchronous operations: publish and subscribe. The semantics of these operations are not clearly defined but they can be understood as asynchronous, non-blocking write and read operations.<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*-yi6YBmO3LHJ5uEd\"><\/figure>\n<p>This boundary makes it possible to look at the evented system as similar to traditional client-server architectures of synchronous RESTful APIs as defined by\u00a0OAS.<\/p>\n<p>This simple model is also incredibly useful in order to treat the evented system as an atomic component that can be reused and provides a clear contract with the exterior, unlocking a lot of productization and lifecycle use cases around the evented\u00a0system.<\/p>\n<p>The second interesting aspect of AsyncAPI when compared to traditional synchronous HTTP based RPC APIs is that AsyncAPI needs to support multiple transports. There are many technologies that can satisfy the simple interface introduced by AsyncAPI. Many of these transports introduce complex application level protocols, but, in the same way OAS uses HTTP as a transport without reusing the application level semantics of the protocol, AsyncAPI can abstract these details and still provide value through the abstract asynchronous operations described in the specification.<\/p>\n<p>However, in order to actually invoke the operations from the external consumer point of view, the abstract operations must be bound to some actual transport component. AsyncAPI bindings capture how to bind that abstract element to the concrete protocol information required to publish and subscribe to the\u00a0events.<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*ufGlwqiZiTs48CUE\"><\/figure>\n<p>From this point of view, we model AsyncAPI as an asynchronous RPC API mechanism with multi-transport bindings. This allows us to encode AsyncAPI specifications in the same graph of metadata with the common semantics we are generating for RAML\/OAS, with some minor adjustments:<\/p>\n<ul>\n<li>AsyncAPI channels are mapped to RPC endpoints in our common\u00a0model<\/li>\n<li>Asynchronous operations have been added to the synchronous operations already supported in each\u00a0endpoint<\/li>\n<li>Events are described using the same schema language as synchronous payloads but attached to asynchronous operations<\/li>\n<li>Transport bindings were added to key elements in the RPC model that becomes an abstract RPC model with concrete\u00a0bindings<\/li>\n<li>HTTP details in the synchronous case have been pushed to the common bindings mechanism<\/li>\n<\/ul>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*nLVT4rFTXokVMDBL\"><\/figure>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*WbbU33YrDuKwOLxI\"><\/figure>\n<p>Reusing the same common semantics allowed us to explain a simple way what role AsyncAPI plays in your evented API lifecycle and, most importantly, to reuse the same tooling and technologies we are already using working with RESTful APIs specified in RAML\/OAS for AsyncAPI (e.g. linting). This opens interesting interoperability between synchronous and asynchronous APIs.<\/p>\n<p>One example of this interoperability is generating wrappers for GraphQL that support synchronous and asynchronous RPC operations, through GraphQL subscriptions, from existing RAML\/OAS and Async\u00a0APIs.<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*K-P65bAilvQ5fn4F\"><\/figure>\n<p>Finally, it is important to note that the simplicity and straight-forward nature of AsyncAPI (as in the case of OAS) also means that many relevant details of the API interface cannot be expressed in these specification languages.<\/p>\n<p>In the same way that is impossible to describe pagination in OAS in a standard way, AsyncAPI does not provide a mechanism to describe whether a particular payload is a command or a regular event, or if an asynchronous operation is part of a pub-sub pattern or it fan-outs as part of a task distribution push-pull pattern.<\/p>\n<p>As both specifications mature, support for these additional patterns could be added on top of the core API model. In our case, one of the benefits of using a common formal model independent of the specification syntax is that we can enrich the model with this kind of extended semantics and make them available for our tooling. Additional pagination semantics can then be expressed in the target specification using and use the standard extension mechanism provided by the specification language (e.g. extensions in OAS and AsyncAPI).<\/p>\n<figure><img decoding=\"async\" alt=\"\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1024\/0*MCwkX-dFV_0vJP0F\"><\/figure>\n<p>Summing up, AsyncAPI is a great mechanism to productize evented systems in the same way OAS has made it possible to treat API as products in the case of \u2018RESTful\u2019 APIs. It has the potential to unlock a new generation of tooling that moves the mindset of the API community in a direction where the distinctions between synchronous APIs and evented systems start to disappear. Our way of treating both types of APIs using a common model that can be consumed by a common set of tools and can be extended to fill gaps in the current specifications is further confirmation of how both types of APIs can be unified in a more general way of designing, cataloguing, discovering, and managing\u00a0APIs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/medium.com\/_\/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=db9873695910\" width=\"1\" height=\"1\" alt=\"\"><\/p>\n<hr>\n<p><a href=\"https:\/\/engineering.salesforce.com\/asyncapi-and-openapi-an-api-modeling-approach-db9873695910\">AsyncAPI and OpenAPI: an API Modeling Approach<\/a> was originally published in <a href=\"https:\/\/engineering.salesforce.com\/\">Salesforce Engineering<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>\n<p><a href=\"https:\/\/engineering.salesforce.com\/asyncapi-and-openapi-an-api-modeling-approach-db9873695910?source=rss----cfe1120185d3---4\" target=\"_blank\" rel=\"noopener\">Read More<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AsyncAPI is gaining traction in the ecosystem of API tools. It solves an important problem: it provides a convenient way of describing the interface of event-driven systems independently of the underlying technology. With AsyncAPI, evented systems can be treated as any other API product: a productizable and reusable, self-describing building block encapsulating some set of&hellip; <a class=\"more-link\" href=\"https:\/\/fde.cat\/index.php\/2021\/02\/02\/asyncapi-and-openapi-an-api-modeling-approach\/\">Continue reading <span class=\"screen-reader-text\">AsyncAPI and OpenAPI: an API Modeling Approach<\/span><\/a><\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":315,"url":"https:\/\/fde.cat\/index.php\/2021\/08\/31\/api-federation-growing-scalable-api-landscapes\/","url_meta":{"origin":221,"position":0},"title":"API Federation: growing scalable API landscapes","date":"August 31, 2021","format":false,"excerpt":"Organizations embrace micro-services and event-driven APIs in their technology platforms to try to achieve the promise of greater agility, increased innovation, and more autonomy for their development teams. However, after the initial success, it is not unusual for organizations to face difficulties when they try to scale their distributed platforms.\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":558,"url":"https:\/\/fde.cat\/index.php\/2022\/03\/29\/investigate-issues-with-ease-by-adding-a-correlation-id-to-your-api\/","url_meta":{"origin":221,"position":1},"title":"Investigate Issues with Ease by Adding a Correlation ID to your API","date":"March 29, 2022","format":false,"excerpt":"With APIs becoming more complex and distributed, developers sometimes struggle to find the relevant logs when they need to investigate a specific issue. In the new Salesforce Commerce APIs (SCAPI), we created such an architecture of distributed systems and recognized this problem early. Our approach to mitigate it was the\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":593,"url":"https:\/\/fde.cat\/index.php\/2022\/03\/29\/investigate-issues-with-ease-by-adding-a-correlation-id-to-your-api-2\/","url_meta":{"origin":221,"position":2},"title":"Investigate Issues with Ease by Adding a Correlation ID to your API","date":"March 29, 2022","format":false,"excerpt":"With APIs becoming more complex and distributed, developers sometimes struggle to find the relevant logs when they need to investigate a specific issue. In the new\u00a0Salesforce Commerce APIs\u00a0(SCAPI), we created such an architecture of distributed systems and recognized this problem early. Our approach to mitigate it was the introduction of\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":499,"url":"https:\/\/fde.cat\/index.php\/2021\/11\/01\/the-journey-of-building-a-scalable-api\/","url_meta":{"origin":221,"position":3},"title":"The Journey of Building a Scalable API","date":"November 1, 2021","format":false,"excerpt":"APIs are an essential tool to allow partners, developers, and applications to consume, communicate\u00a0,or build on top of the various capabilities your microservices provide. Building a high quality API that can scale and perform with the business ecosystem is not easy and requires putting thought and planning into everything, from\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":837,"url":"https:\/\/fde.cat\/index.php\/2024\/03\/12\/from-concept-to-reality-developing-mulesofts-new-flex-gateway-api-management-solution\/","url_meta":{"origin":221,"position":4},"title":"From Concept to Reality: Developing MuleSoft\u2019s New Flex Gateway API Management Solution","date":"March 12, 2024","format":false,"excerpt":"In our \u201cEngineering Energizers\u201d Q&A series, we explore the remarkable journeys of engineering leaders who have made significant contributions in their respective fields. Today, we dive into the technical journey of Evangelina Martinez Ruiz Moreno, a Senior Director at Salesforce, who spearheaded the development of MuleSoft\u2019s new Anypoint Flex Gateway.\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":288,"url":"https:\/\/fde.cat\/index.php\/2021\/08\/31\/building-a-successful-enterprise-ai-platform\/","url_meta":{"origin":221,"position":5},"title":"Building a Successful Enterprise AI Platform","date":"August 31, 2021","format":false,"excerpt":"IntroductionIn 2016, I started as a fresh grad software engineer at a small startup called MetaMind, which was acquired by Salesforce. Since then, it has been quite a journey to achieve a lot with a small team. I\u2019m part of Einstein Vision and Language Platform team. Our platform provides customers\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":1,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":239,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions\/239"}],"wp:attachment":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}