Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add content for module 3 #5

Closed
wants to merge 13 commits into from
244 changes: 244 additions & 0 deletions 100-level-AsyncAPI-Intro/step2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@

## Understanding AsyncAPI Components through Chan and Eve's Programming Session
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Info (Metadata about the API):**

Just as the name tag on Chan's spaceship provides essential details like the spaceship's name and model, the `info` section in AsyncAPI serves a similar purpose. It provides crucial information about the API, such as the title, version, and description. This metadata helps developers understand the basic details of the API they're working with.

```yml
asyncapi: '3.0.0'
info:
title: Space Communication API
version: '1.0.0'
description: API for communication between Chan's spaceship and Capuccinova
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Servers (Communication servers in the API):**

Imagine that Chan's spaceship communicates with Eve on Capuccinova through various servers. In AsyncAPI, the `servers` section describes the servers our API will communicate with, including their hosts, protocols, and descriptions.

```yml
servers:
production:
host: space.mosquitto.org
protocol: mqtt
description: Production server for space communication
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Channels (Communication channels in the API):**
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

The spaceship's radio stations, which correspond to specific topics like communicating with Capuccinova, are simmilar to the `channels` in AsyncAPI. These channels represent paths for sending specific types of messages. Each channel uses an address, which is a template for the URI of the server, and can have variables inside curly braces.

```yml
channels:
roomidchat:
address: chat/{roomId}
messages:
chatMessage:
name: ChatMessage
payload:
type: object
properties:
userId:
type: string
description: The ID of the user who sent the message
message:
type: string
description: The chat message
spacename:
type: string
description: The unique spacename identifier for the message
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Tags (Categorizing operations):**

`Tags` in AsyncAPI are like the labels on the spaceship's control panel. They help categorize different operations, making it easier for developers to understand what each part of the API does. Each tag consists of a name and an optional description.

```yml
tags:
- name: chat
description: Operations related to chat
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Components (Reusable parts of the API):**

`Component` is like the toolbox in Chan's spaceship. It contains reusable parts like message definitions and schemas that can be used across the API. Each component is linked to a particular schema, which describes the structure of the message content.

```yml
components:
messages:
ChatMessage:
name: ChatMessage
title: Chat Message
contentType: application/json
payload:
$ref: '#/components/schemas/ChatMessagePayload'
schemas:
ChatMessagePayload:
type: object
properties:
userId:
type: string
description: The ID of the user who sent the message
message:
type: string
description: The chat message
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

## Programming Operations, Messages, and Schemas
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Operations (Defined actions within channels):**

`Operations` in AsyncAPI are like the instructions for the spaceship. They define what actions can be performed within each channel, such as sending or receiving messages. Each operation is associated with a message and a schema.

```yml
operations:
sendChatMessage:
action: 'send'
summary: Send a chat message to a specific room
channel:
$ref: '#/channels/roomidchat'
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
- **Messages (Content of the operations):**

`Messages` in AsyncAPI are the content exchanged during operations, just like the words Eve from Capuccinova and Chan from Brownieterra use to communicate. They describe the structure and content of the messages sent or received.


```yml
components:
messages:
ChatMessage:
name: ChatMessage
title: Chat Message
contentType: application/json
payload:
$ref: '#/components/schemas/ChatMessagePayload'
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **Schemas (Structure of message content):**

`Schemas` in AsyncAPI are like the blueprints for the spaceship. They define the structure of the message content, ensuring that everything fits together correctly. Each schema is associated with a component and describes the structure and content of the messages.

```yml
components:
schemas:
ChatMessagePayload:
type: object
properties:
userId:
type: string
description: The ID of the user who sent the message
message:
type: string
description: The chat message
```
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

---

Certainly! Here's the updated hands-on exercise, guiding you through the entire process of creating and configuring Chan's AsyncAPI document for communication with Capuccinova and beyond.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhmohona This line shows clear plagiarism from chatgpt.

### Chan's Galactic Coding Adventure: Crafting the Capuccinova Connection

#### Prologue: A New Beginning in the Stars

Chan embarks on a mission to establish a sophisticated communication system with Eve on Capuccinova. With your expertise in AsyncAPI, you'll assist him in creating a robust AsyncAPI document from scratch.

---
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

#### Chapter 1: Initiating the Capuccinova Communication Link
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

**Your Mission: Creating the Base AsyncAPI Document**
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

1. **Start the Journey**: In the KillerCoda terminal, create a new file by typing `nano chan-to-capuccinova.yaml`.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

2. **Lay the Cosmic Foundations**: Enter the basic AsyncAPI structure:
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
```yaml
asyncapi: 3.0.0
info:
title: Space Communication API
version: '1.0.0'
description: API for communication between Chan's spaceship and Capuccinova

servers:
production:
host: space.mosquitto.org
protocol: mqtt
description: Production server for space communication

channels:
roomidchat:
address: chat/{roomId}
messages:
chatMessage:
name: ChatMessage
payload:
type: object
properties:
userId:
type: string
description: The ID of the user who sent the message
message:
type: string
description: The chat message
spacename:
type: string
description: The unique spacename identifier for the message

operations:
sendChatMessage:
action: 'send'
summary: Send a chat message to a specific room
channel:
$ref: '#/channels/roomidchat'
```
3. **Seal the Galactic Document**: Save (`Ctrl + O`, `Enter`) and exit Nano (`Ctrl + X`).

4. **Inform Chan**: Let him know that the foundation for his AsyncAPI document is set.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

#### Chapter 2: Expanding the Network to Brownieterra

**Your Mission: Adding a New Channel and Defining Operations for Brownieterra**

After successfully laying the groundwork for communication with Capuccinova, Chan is now eager to extend his AsyncAPI document to include a channel for Brownieterra.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

1. **Reopen the AsyncAPI Document**: Use the command `nano chan-to-capuccinova.yaml` to edit Chan's document.

2. **Create a New Communication Channel**: Add a channel for Brownieterra. This includes specifying the channel name, its address, and parameters:
```yaml
brownieterra-chat:
description: Channel for sending messages to Brownieterra
address: brownieterra-chat/{spacename}
parameters:
spacename:
description: The unique spacename identifier for Brownieterra communication
schema:
type: string
```

3. **Define Operations for the New Channel**: Under the `operations` section, specify how messages will be sent over the new Brownieterra channel. For example:
```yaml
operations:
sendToBrownieterra:
action: send
summary: Send a message to Brownieterra
channel:
$ref: '#/channels/brownieterra-chat'
```

4. **Save and Exit**: After adding the new channel and defining its operations, save your changes (`Ctrl + O`, `Enter`) and exit Nano (`Ctrl + X`).

5. **Inform Chan**: Let Chan know that the new channel for Brownieterra has been successfully added and configured in his AsyncAPI document.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

#### Chapter 3: Perfecting the Message Structure

**Your Mission: Enhancing Message Formats and Payloads**

Chan wants to add more details to the message payloads for more personalized communication.

1. **Access the AsyncAPI File**: Edit `chan-to-capuccinova.yaml` in Nano.

2. **Refine the Message Payloads**: Update the payloads to include additional properties or modify existing ones to better suit the communication needs.

3. **Consolidate the Changes**: Save your modifications (`Ctrl + O`, `Enter`) and exit (`Ctrl + X`).

4. **Update Chan**: Let him know that the message formats are now more detailed and well structured for both Capuccinova and Brownieterra.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved