nodejs

    科技2022-08-03  122

    nodejs

    昂首阔步 (What is Swagger)

    Swagger is the largest framework for designing APIs using a common language with including documentation, design, testing, and deployment. Swagger easily comprehensible for both developers and non-developers. Thus, software developers, product and project managers, business analysts, etc can access API design. Also, as Swagger is easily adjustable, it can be successfully used for API testing and bug fixing.

    Swagger是使用通用语言(包括文档,设计,测试和部署)来设计API的最大框架。 Swagger对于开发人员和非开发人员都很容易理解。 因此,软件开发人员,产品和项目经理,业务分析师等可以访问API设计。 另外,由于Swagger易于调整,因此可以成功地用于API测试和错误修复。

    There are 2 packages are used for integrating swagger with APIs in nodejs:

    有2个用于将swagger与API集成到nodejs中的软件包:

    swagger-jsdoc

    swagger-jsdoc

    swagger-ui-express

    swagger-ui-express

    用法 (Usage)

    Install using npm:

    使用npm安装:

    npm i swagger-jsdoc swagger-ui-express

    after that define routes in the main file called server.js and integrate swagger code for per API.

    之后,在名为server.js的主文件中定义路由,并为每个API集成swagger代码。

    To check the swagger API documentation

    查看swagger API文档

    Run the server:

    运行服务器:

    npm run start

    npm运行开始

    2. Open chrome and past server IP address like:

    2.打开chrome和过去的服务器IP地址,例如:

    http://localhost:3000/api-docs/

    http:// localhost:3000 / api-docs /

    It looks like

    看起来像

    Yeah! We successfully integrated Swagger 🎉

    是的 我们成功整合了Swagger🎉

    翻译自: https://medium.com/nonstopio/nodejs-with-swagger-2fd26ea02436

    nodejs

    相关资源:node-microservice-demo:Micro用于微服务的示例项目,带有Node TypeScript Express Swagger Docker-源码
    Processed: 0.012, SQL: 8