「仮想サーバ/docker/MockApiサーバ」の版間の差分
提供: 初心者エンジニアの簡易メモ
| (同じ利用者による、間の4版が非表示) | |||
| 行3: | 行3: | ||
dockerhubのmmock:https://hub.docker.com/r/jordimartin/mmock | dockerhubのmmock:https://hub.docker.com/r/jordimartin/mmock | ||
| + | |||
| + | docker-compose.yml | ||
| + | <pre> | ||
| + | services: | ||
| + | mmock: | ||
| + | image: jordimartin/mmock:latest | ||
| + | restart: 'always' | ||
| + | volumes: | ||
| + | - ./mmock:/config | ||
| + | ports: | ||
| + | - '8082:8082' | ||
| + | - '8083:8083' | ||
| + | </pre> | ||
| + | mmock/helloworld.yml | ||
| + | <pre> | ||
| + | request: | ||
| + | method: GET | ||
| + | path: "/hello/*" | ||
| + | response: | ||
| + | statusCode: 200 | ||
| + | headers: | ||
| + | Content-Type: | ||
| + | - application/json | ||
| + | body: '{"hello": "{{request.query.name}}, my name is {{fake.FirstName}}"}' | ||
| + | </pre> | ||
| + | |||
| + | 実行し、コンテナを稼働させる | ||
| + | $ docker-compose up | ||
| + | |||
| + | APIリスト管理画面 | ||
| + | ttp://0.0.0.0:8082 | ||
| + | |||
| + | httpアクセス | ||
| + | ttp://0.0.0.0:8083/hello?name=helloworld | ||
| + | |||
| + | {"hello": "helloworld, my name is Catherine"} | ||
| + | |||
| + | methodには、GET|POST|PUT|PATCHが使える | ||
参考:https://qiita.com/Ryo478468/items/4a959c5d7312045f471c | 参考:https://qiita.com/Ryo478468/items/4a959c5d7312045f471c | ||
| 行14: | 行52: | ||
以下でswagger-uiのapi設定のAPIリストが出る | 以下でswagger-uiのapi設定のAPIリストが出る | ||
| − | ttp://localhost:8090 | + | httpアクセス ttp://localhost:8090 |
| − | + | サンプルでxmlを表示したい場合 | |
#/pet/findByStatusを開いて、try it outを選択 | #/pet/findByStatusを開いて、try it outを選択 | ||
#availableを選択 | #availableを選択 | ||
2021年2月1日 (月) 19:20時点における最新版
mmockでサーバを作成
go言語で作られたmockAPIサーバー jordimartin/mmockを使う。
dockerhubのmmock:https://hub.docker.com/r/jordimartin/mmock
docker-compose.yml
services:
mmock:
image: jordimartin/mmock:latest
restart: 'always'
volumes:
- ./mmock:/config
ports:
- '8082:8082'
- '8083:8083'
mmock/helloworld.yml
request:
method: GET
path: "/hello/*"
response:
statusCode: 200
headers:
Content-Type:
- application/json
body: '{"hello": "{{request.query.name}}, my name is {{fake.FirstName}}"}'
実行し、コンテナを稼働させる
$ docker-compose up
APIリスト管理画面 ttp://0.0.0.0:8082
httpアクセス ttp://0.0.0.0:8083/hello?name=helloworld
{"hello": "helloworld, my name is Catherine"}
methodには、GET|POST|PUT|PATCHが使える
参考:https://qiita.com/Ryo478468/items/4a959c5d7312045f471c
Swaggerapiでサーバー作成
docker pull swaggerapi/swagger-ui docker run -d -p 8090:8080 swaggerapi/swagger-ui
以下でswagger-uiのapi設定のAPIリストが出る
httpアクセス ttp://localhost:8090
サンプルでxmlを表示したい場合
- /pet/findByStatusを開いて、try it outを選択
- availableを選択
requestに https://petstore.swagger.io/v2/pet/findByStatus?status=available とでるので、表示するとxmlが出る。
参考:https://qiita.com/aucfan-engineer/items/5532fcf69b4f4dcd1c41
