0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ベースURLの設定方法

Posted at

ベースURLとは?

★相対パスの基準URL(例:http://localhost/)
★すべてのAPIパスは相対パス(よく忘れるから気をつける)
★すべてのAPIエンドポイントはベースURLを基準としている

SwaggerのベースURLの設定方法

SwaggerのserversってところにベースURLを設定することができる

書き方はコチラ💁
API Server and Base URL(公式ドキュメント参照)
API Host and Base URL(公式ドキュメント参照)

例えば、本番環境のベースURLと検証用のベースURLを複数もつことができて、Swagger UIでこれを切り替えることができる。

1、Swagger EditorのserversにAPIサーバのベースURLを指定する

2、Swagger UIにドロップダウンメニューで指定したベースURLを選択する

17.png

すべてのAPIパスは、相対パスです。

3、Swagger UIのテスト実行(省略)

詳しくは、コチラ💁Swaggerでテストする方法
「Try it out」をクリック ⇒ 「Execute」をクリック

4、テスト結果の表示

18.png

レスポンスの中に「**'http://api.example.com/v1/session/register' **」があります。動作確認完了です。

APIサーバっていうとちょっとインフラって感じもしますね。

参考記事:

API Server and Base URL
API Host and Base URL
Swagger(OpenAPI3.0)に入門する(基本構成編)
Web API入門#3 〜URIの基礎知識〜
swagger/OpenAPI 3.0で本番と検証用のURLを明示的に示す
OpenAPI (Swagger) 超入門

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?