LoginSignup
0
0

More than 3 years have passed since last update.

Aspida で Response Header や Status Code を取得する

Last updated at Posted at 2020-11-16

要約

リクエスト時に $ を付けないと Header や Status が含まれた生のレスポンスデータが手に入る

client.v1.hello.$post
ではなく、
client.v1.hello.post

サンプルコード

Aspida定義
api/v1/hello/index.ts

export interface Methods {
    post: {
        query: {
            "api-version": "2019-9-21" | "2020-11-16"
        };
        reqHeaders: {
            "token": string
        };
        reqBody: {
            "name": string
        };
        resHeaders: {
            status: string
        }
        resBody: {
            state: string
            massage: string
            properties: {
                date: string
                uuid: string
                location: string
            }
        }
    }
}

メインコード

import aspida from '@aspida/axios';
import api from '../api/$api';

const RequestTest = async function () {
    const client = api(aspida())
    const res = client.v1.hello.post({
        "query": {
            "api-version": "2020-11-16"
        },
        "header": {
            "token": "ZZZZ-ZZZZ-ZZZZ-ZZZZ"
        },
        "body": {
            "name": "Gen Key"
        }
    })

    // status
    console.log(res.status)
    // headers
    console.log(res.headers)
}

export default RequestTest;
生成された$api.tsを見たらわかった

※動作確認してません

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