LoginSignup
0
0

More than 1 year has passed since last update.

HTTPメソッドの取得方法

Posted at

AzureFunctionsでリクエストのHTTPメソッド判定方法の備忘録です。
下記のコードの通り、req.methodからHTTPメソッドを取得することができます。

index.js
module.exports = async function (context, req) {
    const http_method = req.method; 
    if (http_method == "GET") {
        # GETの処理
    } else if (http_method == "POST") {
        # POSTの処理
    }

なおリスクエスト情報はreqとバインドさせています。

function.json
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

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