1
2

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.

VS Codeの拡張機能REST Client

Posted at

VSCodeの拡張機能REST Clientを使用してAPIを呼び出すのが簡単で使いやすかったので設定方法をご紹介します。

sample setting
@username = "JohnDoe"
@password = "myPassword123"
@url = https://example.com/api/

##############################
POST {{url}}/login
Content-Type: application/json

{
    "username": "{{username}}",
    "password": "{{password}}"
}

##############################

Get {{url}}/user
Content-Type: application/json

##############################

ファイル名には.httpという拡張子を使用します。
この例では、変数@username@passwordにそれぞれの値を代入し、リクエストボディ内のusernamepasswordのフィールドにそれぞれの値を代入しています。

また、変数名にはアルファベットや数字、アンダースコア、ハイフンを使用できますが、先頭に数字を使用することはできません。また、変数名は大文字と小文字が区別されます。

@urlという変数にAPIのURLを代入し、リクエスト内で{{url}}のように変数を参照しています。このように変数を使用することで、APIのURLを変更する場合には、@url変数の値を変更するだけで済みます。

また、変数を使用することで、APIのURLに含まれるパスパラメーターやクエリパラメーターの値も変数化することができます。このようにして、APIのURL内のすべてのパラメーターを一元管理し、簡単に変更できるようにすることができます。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?