Skip to content

Instantly share code, notes, and snippets.

@smoya

smoya/suggestion1.md Secret

Created Mar 23, 2021
Embed
What would you like to do?
[AsyncAPI] Intent-driven API suggestion example

DISCLAIMER: Not native at JS, code has not been tested. Just an illustrative example.

Examples for the Parser Intent-driven API.

Channels

Intents

  • asyncapi.channelsApplicationPublishesTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe())

  • asyncapi.channelsApplicationSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasPublish())

  • asyncapi.channelsClientCanPublishTo() -> asyncapi.channels().filter(channel => channel.hasPublish())

  • asyncapi.channelsClientCanSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe())

  • asyncapi.messagesApplicationPublishesTo() -> asyncapi.channelsApplicationPublishesTo().map(function(channel) {return channel.subscribe().message};)

  • asyncapi.messagesApplicationSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasPublish()).map(function(channel) {return channel.publish().message};)

  • asyncapi.messagesClientCanPublishTo() -> asyncapi.channels().filter(channel => channel.hasPublish()).map(function(channel) {return channel.publish().message};)

  • asyncapi.messagesClientCanSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe()).map(function(channel) {return channel.subscribe().message};)

Getters (we still keep them)

  • message.getOperations() (Due to the current spec, only one operation is linked to a particular message)
  • message.getPayload()

Servers

  • asyncapi.bindings('kafka') -> Return all the bindings from all possible places:
    • servers
    • channels
    • operations
    • messages
  • asyncapi.bindings('kafka', 'servers') -> Return kafka binding for servers
  • asyncapi.bindings('kafka', 'servers', 'name-of-server1', 'name-of-server2') -> Return kafka binding for specific servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment