V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Wanten
V2EX  ›  程序员

各位是如何整理 API 的?

  •  
  •   Wanten · 285 天前 · 1160 次点击
    这是一个创建于 285 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用过 postman ,可以把 api 保存到上面,而且可以附带实例。但有时候觉得不太方便,加载、浏览问题。

    目前是把 API 写到 notion 里,可以放代码,也可以添加文字说明。

    展示 API 的格式用过 Table 、JSON 、YAML

    这是 JSON 的例子:

    Update a specific collection

    {
      "endpoint": "/collection/update?collection_id=uuid",
      "method": "POST",
      "header": {
        "Authorization": "Bearer token"
      },
      "body": {
        "name": "string (required)",
        "description": "string (optional)"
      },
      "response": [
        {
          "code": 200,
          "message": "Success",
          "data": [
            {
    		  "id": "cfcb92e9-9455-4756-94b4-5e93d36941b0",
    		  "owner": "test",
    		  "name": "test",
    		  "description": "",
    		  "created_at": "2023-06-24T08:09:44.585915",
    		  "updated_at": "2023-06-25T07:17:28.229913"
    		}
          ]
        },
        {
          "code": 400,
          "message": "Bad Request / Invalid Collection ID / Invalid Name"
        },
        {
          "code": 401,
          "message": "Email Verification Required"
        },
        {
          "code": 401,
          "message": "Unauthorized"
        }
      ]
    }
    

    Table 格式:

    Path Method Params Header Body Response Comment
    /api/foo GET - - - 200 OK Fetches data from /api/foo
    /api/bar POST key - JSON 201 Created Creates a new resource
    /api/baz PUT id - JSON 200 OK Updates resource with id

    个人喜欢 JSON 格式整理 API ,能展示的信息更多。但往往几个 API 就能写好几页,有大部分是重复的,但又不太好省略。

    不知道大家有没有更好的方法或工具,可以方便查阅、管理 API ?

    感谢!

    4 条回复    2023-07-20 15:44:34 +08:00
    wind1986
        1
    wind1986  
       285 天前   ❤️ 1
    用 swagger, 然后导出
    jaylee4869
        2
    jaylee4869  
       285 天前   ❤️ 1
    tsanie
        3
    tsanie  
       285 天前   ❤️ 1
    OAS 3.0 ,我喜欢用 redoc 做呈现,好看些
    jiammbeyond
        4
    jiammbeyond  
       285 天前
    yapi
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4825 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:41 · PVG 17:41 · LAX 02:41 · JFK 05:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.