Document Your API with Swagger And Docker

微信扫一扫,分享到朋友圈

Document Your API with Swagger And Docker

When developing an API, it’s good to map out what the endpoints are going to be, before actually building the API.
This way other developers will know how they will be able to interface with your API, even before it’s built.
If you already have an API, it’s useful to document the endpoints in a manner that makes it easy for others to integrate with your API without having to perform a lot of guesswork and reading.

Steps

To achieve this, I use a PHP package
(I created) to generate a swagger.json
file.
However, if you want to, you can read the specifications
to manually type out your own swagger.json file.
The swagger.json
file is just a JSON file that describes your API.
I developed the package to make it much easier, and prevent myself having to look things up all the time. I will include a video demonstration at a later date.

Once you have generated your swagger.json file you can use docker to deploy an intuitive website ( swagger UI
) that will use your specification, and that others can use to see how your API works, and even try it out.

#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

docker run --name swaggerui -p 80:8080 
  -v $DIR:/swaggerui/swagger 
  metz/swaggerui

This script expects to be run from within the folder that contains your swagger.json
file.

微信扫一扫,分享到朋友圈

Document Your API with Swagger And Docker

特斯拉将在北京时间3月15日上午11时发布Model Y

上一篇

[菜鸟SpringCloud入门]第三章:将Eureka改造为高可用集群

下一篇

你也可能喜欢

Document Your API with Swagger And Docker

长按储存图像,分享给朋友