要在APIary中创建和存储变量,您可以使用API Blueprint的Attributes和Parameters部分来定义和描述变量。以下是一个示例:
FORMAT: 1A
# My API
## Group MyGroup
### My Endpoint [/my-endpoint/{id}]
+ Parameters
+ id: `123` (required, number) - The ID of the endpoint
+ Attributes
+ name: John Doe (string, required) - The name of the user
+ age: 25 (number, required) - The age of the user
## Group Variables
### Set Name [POST /variables/name]
Use this endpoint to set the name variable.
+ Request (application/json)
+ Body
{
"name": "John Doe"
}
### Get Name [GET /variables/name]
Use this endpoint to get the value of the name variable.
+ Response 200 (application/json)
+ Body
{
"name": "John Doe"
}
在上面的示例中,我们定义了一个名为“name”的变量,并在/variables/name
端点上创建了两个操作:Set Name
和Get Name
。Set Name
操作用于设置变量的值,Get Name
操作用于获取变量的值。
您可以使用Set Name
端点来设置变量的值,然后使用Get Name
端点来获取变量的值。这些端点可以使用API Blueprint的请求和响应部分进行测试。
请注意,上述示例仅用于说明如何在APIary中创建和存储变量。实际上,APIary并不提供真正的变量存储功能。要在实际的应用程序中存储和管理变量,您需要使用后端服务器和数据库。