Skip to content

Instantly share code, notes, and snippets.

@mhmohona
Last active November 14, 2023 01:17
Show Gist options
  • Select an option

  • Save mhmohona/e2a65d26f1a2eae04b73ec3a6aad4752 to your computer and use it in GitHub Desktop.

Select an option

Save mhmohona/e2a65d26f1a2eae04b73ec3a6aad4752 to your computer and use it in GitHub Desktop.
mod3 discription

Module 3

Let's delve deeper into these components:

  • info: info section provides metadata about the API, such as its title and version
  • channels: channels section defines the communication channels used by the API. Each channel corresponds to a specific topic or queue in the message broker. The channels section includes the type of messages sent on each topic/queue
  • components: components section defines reusable components that can be referenced elsewhere in the API definition. This can include message definitions, schemas, parameters, and more. By defining these components in one place, you can maintain consistency across your API
  • tags: tags section allows you to categorize operations in your API. It can be useful for grouping related operations together, making the API easier to navigate and understand.
  • Operations: operations are defined within channels. For example, a send operation might be defined for a channel to specify that messages are sent by that channel.
  • Messages: Messages are defined within operations and specify the content of the messages that are sent or received on a channel. Each message can have a name, title, summary, contentType, and payload. The payload describes the structure of the message content, and it can reference a schema defined in the components section
  • Schemas: Schemas are defined in the components section and describe the structure of message content. They can be referenced by messages to define their structure. Schemas can be simple types like string or integer, or they can be complex types like object or array

Module 4

A: Writing an AsyncAPI document from scratch involves several steps. This process can be broken down into the following parts:

  1. Defining the AsyncAPI version and general information The first section of the AsyncAPI document specifies the AsyncAPI version and general information about the API. This includes the title, version, and description of the API. For example:
asyncapi: 3.0.0
info:
  title: Sending Signal to Eve
  version: 0.1.0

In this section, asyncapi: 3.0.0 specifies that the document is written following version 3.0.0 of the AsyncAPI specification. The info: section provides more detail about the API itself.

  1. Defining the channels and messages The next part involves defining the channels and messages that the API uses. Channels represent the routes where messages are sent or received, while messages represent the data being transferred. For example:
channels:
  userSignedUp:
    address: Earth/letter
    messages:
      lettertoEarth:
        description: Communicating with Eve.
        payload:
          type: object
          additionalProperties: false
          properties:
            fullName:
              type: string
            email:
              type: string
              format: email
            age:
              type: integer
              minimum: 18

In this case, the document specifies a userSignedUp channel with an address of Earth/letter. The lettertoEarth message is sent on this channel and includes the user's full name, email, and age in the payload.

  1. Defining the operations Lastly, operations represent the actions that can be performed on channels. They specify whether the API sends (publish) or receives (subscribe) messages on a particular channel. For example:
operations: 
  userSignedUp:
    action: send
    channel: 
      $ref: '#/channels/lettertoEarth'

Here, the API is specified to send (action: send) messages on the userSignedUp channel.

Q: Using AsyncAPI tools for validating the document?

A: AsyncAPI studio.

Q: Hands-on exercises to create and validate AsyncAPI documents?

A: Here's an exercise you can do to practice creating and validating AsyncAPI documents:

Using the example AsyncAPI document provided, modify the payload section to add a new property for username of type string. Add a new channel named userLoggedIn with an address of Mars/letter and a message named lettertoMars. Validate your updated AsyncAPI document using the AsyncAPI studio. Remember to carefully follow the AsyncAPI specification when adding new components to your document.

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