Skip to content

Commit

Permalink
Merge branch 'master' into doc-intro-asyncapi-document
Browse files Browse the repository at this point in the history
  • Loading branch information
quetzalliwrites authored Dec 12, 2023
2 parents f5895b4 + 96af1dc commit 49ba858
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 50 deletions.
6 changes: 0 additions & 6 deletions components/MDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ export function getMDXComponents() {
td: props => <td {...props} className={`${props.className || ''} px-6 py-4 border-b border-gray-200 text-sm leading-5 text-gray-700 tracking-tight`} />,
pre: props => CodeComponent(props.children.props),
code: props => <code {...props} className={`${props.className || ''} px-1 py-0.5 bg-gray-200 text-gray-800 rounded font-mono text-sm`} />,
details: (props) =>
<details {...props} className={`${ props.className || ''} mb-1 font-heading antialiased text-gray-900`}/>,
summary: (props) =>
<summary {...props} className={`${props.className || ''} my-2 font-heading cursor-pointer antialiased font-semibold text-gray-900`}/>,
p: (props) =>
<p {...props} className={`${props.className || ''} ml-4 cursor-pointer`}/>,
hr: props => <hr {...props} className={`${props.className || ''} my-8`} />,
CodeBlock,
ChapterSuggestions,
Expand Down
52 changes: 8 additions & 44 deletions pages/about/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,47 +100,11 @@ All the information about the project's economy, the amount of the donations, th

## FAQs

<details class="cursor-pointer">
<summary>What is the goal of the project?</summary>

<p> To make asynchronous APIs as successful and mature as REST APIs.</p>

</details>

<details class="cursor-pointer ">
<summary>What protocols does it support?</summary>

<p>AsyncAPI is protocol-agnostic, so you can use it for APIs that work over any protocol (e.g., AMQP, MQTT, WebSockets, Kafka, STOMP, HTTP, Mercure, etc). For more information, refer to the [AsyncAPI specification documentation](https://www.asyncapi.com/docs/reference/specification/latest#serverBindingsObject).
</p>

</details>

<details class="cursor-pointer">
<summary>Who are the users of AsyncAPI?</summary>

<p>AsyncAPI users are those who implement and maintain event-driven architecture. For example, people that write backend API using WebSocket, or people that maintain communication between their microservices using Kafka.</p>

</details>

<details class="cursor-pointer">
<summary>What is the AsyncAPI Community?</summary>

<p>It’s the core of the initiative. The AsyncAPI community contributes to the development of the tool, it promotes access and distribution of the specification allowing freedom of use, study, copying, modification, and redistribution to anyone who wishes to do so. The cooperation between these people in all areas of software production generates a substantial improvement in the quality of the software, as well as greater dissemination and sustainability over time, and prioritizing the benefit of society over any other.</p>

</details>

<details class="cursor-pointer">
<summary>Who can use it?</summary>

<p>Anyone. All projects under AsyncAPI Initiative are part of the Linux Foundation, licensed under the Apache 2.0 license. It’s open to use and contribution.</p>

</details>

<details class="cursor-pointer">
<summary>Where can I find more information?</summary>

&nbsp;[Official AsyncAPI Documentation](/docs)

&nbsp;[Presentation by Fran Méndez, explaining the project](https://www.youtube.com/watch?v=UID1nnuFDtM&list=PLbi1gRlP7piitNgvqhIAvGNZM_kvP0r8R)

</details>
- **What is the goal of the project?** To make asynchronous APIs as successful and mature as REST APIs.
- **What protocols does it support?** AsyncAPI is protocol-agnostic, so you can use it for APIs that work over any protocol (e.g., AMQP, MQTT, WebSockets, Kafka, STOMP, HTTP, Mercure, etc). For more information, refer to the [AsyncAPI specification documentation](https://www.asyncapi.com/docs/reference/specification/latest#serverBindingsObject).
- **Who are the users of AsyncAPI?** AsyncAPI users are those who implement and maintain event-driven architecture. For example, people that write backend API using WebSocket, or people that maintain communication between their microservices using Kafka.
- **What is the AsyncAPI Community?** It’s the core of the initiative. The AsyncAPI community contributes to the development of the tool, it promotes access and distribution of the specification allowing freedom of use, study, copying, modification, and redistribution to anyone who wishes to do so. The cooperation between these people in all areas of software production generates a substantial improvement in the quality of the software, as well as greater dissemination and sustainability over time, and prioritizing the benefit of society over any other.
- **Who can use it?** Anyone. All projects under AsyncAPI Initiative are part of the Linux Foundation, licensed under the Apache 2.0 license. It’s open to use and contribution.
- **Where can I find more information?**
- [Official AsyncAPI Documentation](/docs)
- [Presentation by Fran Méndez, explaining the project](https://www.youtube.com/watch?v=UID1nnuFDtM&list=PLbi1gRlP7piitNgvqhIAvGNZM_kvP0r8R)
136 changes: 136 additions & 0 deletions pages/docs/concepts/asyncapi-document/variable-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: Server variables
weight: 275
---

The server's URL consists of the `host` and `pathname` fields. These values are not always known when you design your system. AsyncAPI enables you to construct dynamic URLs while enhancing the flexibility and maintainability of your AsyncAPI documents. These dynamic values (variables) are placeholders for values you can replace during runtime. You can easily manage multiple endpoints, handling various server configurations and environments.

## Add variables

You can add variables to `server.host` and `server.pathname` by adding a variable between curly braces like `{braces}`. Next, you use `server.variables` to provide definitions of your variables. Finally, leverage `components.serverVariables` to enable reusable variable definitions across multiple servers.

The diagram below describes how to use reusable variables in AsyncAPI.

```mermaid
graph LR
C[servers]
F[host]
I[protocol]
E[pathname]
A[components]
B[serverVariables]
D[variables]
C --> F
C --> I
C --> E
C --> D
D --> |$ref| B
A --> B
style C fill:#47BCEE,stroke:#000;
style D fill:#47BCEE,stroke:#000;
style F fill:#47BCEE,stroke:#000;
style E fill:#47BCEE,stroke:#000
```

First, configure the variables in `host` and/or `pathname`. Next, define reusable variables in `components.serverVariables`. Finally, ensure that your `server.variables` from the server reference definitions in the `components.serverVariables` uses `$ref`.

### Servers section

Define the servers section in your AsyncAPI document, including the `host` and `pathname` for your API servers. Use placeholders enclosed in curly braces {} to represent the variables in the server. For example:

```yaml
servers:
production:
host: '{subdomain}.example.com:{port}'
pathname: '/{version}
variables:
subdomain:
enum:
- development
- staging
- production
port:
default: '8080'
version:
enum:
- v1
- v2
```
### `serverVariables` section

Define the `components.serverVariables` section in your AsyncAPI document. For each variable used in the server `host` or `pathname`, provide a default value and an optional description to avoid repeating the variable definitions. For example:

```yaml
components:
serverVariables:
subdomain:
enum:
- development
- staging
- production
default: development
port:
default: '8080'
version:
enum:
- v1
- v2
```

### Define domain and port variables

Use `components.serverVariables` in your server using the [Reference Object](/docs/reference/specification/v3.0.0#referenceObject) to avoid repeating information:

```yml
variables:
subdomain:
$ref: '#/components/serverVariables/subdomain'
```

Here's the complete AsyncAPI document with the servers' variables for the `host` field:

```yaml
asyncapi: 3.0.0
info:
title: Example API
version: '1.0.0'
servers:
production:
host: '{subdomain}.example.com:{port}'
pathname: '/{version}'
protocol: amqp
variables:
subdomain:
$ref: '#/components/serverVariables/subdomain'
port:
$ref: '#/components/serverVariables/port'
version:
$ref: '#/components/serverVariables/version'
development:
host: '{subdomain}.dev.example.com:{port}'
pathname: /v1
protocol: amqp
variables:
subdomain:
$ref: '#/components/serverVariables/subdomain'
port:
$ref: '#/components/serverVariables/port'
version:
$ref: '#/components/serverVariables/version'
components:
serverVariables:
subdomain:
enum:
- development
- staging
- production
default: development
port:
default: '8080'
version:
enum:
- v1
- v2
```

0 comments on commit 49ba858

Please sign in to comment.