[英]How to create an API through a pre-defined backend in an .yml file?
我有一个.yml
文件,其中包含定义一组用于创建和读取帐户交易的操作的规范。 这个文件是创建我的API
的规范。
我使用editor.swagger.io
查看我的API
的规格。
我如何测试这个 API? 真的创建有效的 HTTP 请求吗? 如何生成链接并能够在postman
上进行测试,例如这个 API?
我对后端知之甚少,我真的不知道如何处理这个.yml
文件,但我需要创建一个有效的 API。 你能告诉我该怎么做吗?
openapi: 3.0.0 info: title: Account Management API version: 1.0.0 components: schemas: Amount: type: object properties: account_id: type: string format: uuid amount: type: integer required: - account_id - amount Balance: type: object properties: balance: type: integer required: - amount examples: PositiveAmount: value: account_id: '0afd02d3-6c59-46e7-b7bc-893c5e0b7ac2' amount: 7 NegativeAmount: value: account_id: '5ae0ef78-e902-4c40-9f53-8cf910587312' amount: -4 PositiveBalance: value: balance: 10 paths: /amount: post: summary: Updates account balance with amount. parameters: - in: header name: Transaction-Id schema: type: string format: uuid example: 'cf479136-0a5b-42ad-a16c-26d9eda3b4aa' required: true requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Amount' examples: PositiveAmount: $ref: '#/components/examples/PositiveAmount' NegativeAmount: $ref: '#/components/examples/NegativeAmount' responses: '200': description: Operation accepted. '400': description: Mandatory body parameters missing or have incorrect type. '405': description: Specified HTTP method not allowed. '415': description: Specified content type not allowed. /balance/{account_id}: get: summary: Returns current account balance. parameters: - name: account_id in: path required: true description: Account ID. schema: type: string format: uuid example: '5ba6e1b0-e3e7-483a-919a-a2fc17629a90' responses: '200': description: Account balance. content: application/json: schema: $ref: '#/components/schemas/Balance' examples: PositiveBalance: $ref: '#/components/examples/PositiveBalance' '404': description: Account not found. /transaction/{transaction_id}: get: summary: Returns transaction details. parameters: - name: transaction_id in: path required: true description: Transaction ID. schema: type: string format: uuid example: '023d2024-24bc-42c9-ab24-689eef6ea0f9' responses: '200': description: Transaction details. content: application/json: schema: $ref: '#/components/schemas/Balance' examples: PositiveBalance: $ref: '#/components/examples/PositiveBalance' '404': description: Transaction not found
非常感谢您提供任何提示、教程或类似的东西!!
根据您最喜欢的后端编程语言,您可以使用不同的解决方案 go。
例如,您可以使用这个 package 设置一个 expressjs 后端服务器:
您还需要了解部署、数据库等方面的知识:
网上有很多教程。
祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.