HTTPリンク
非公式ベータ版翻訳
このページは PageTurner AI で翻訳されました(ベータ版)。プロジェクト公式の承認はありません。 エラーを見つけましたか? 問題を報告 →
httpLinkは終端リンクで、HTTP経由でtRPC操作をtRPCプロシージャに送信します。
httpLinkはPOSTリクエストとGETリクエストの両方をサポートしています。
使用方法
以下のようにhttpLinkをインポートしてlinks配列に追加できます:
client/index.tstsimport {createTRPCClient ,httpLink } from '@trpc/client';import type {AppRouter } from './server';constclient =createTRPCClient <AppRouter >({links : [httpLink ({url : 'http://localhost:3000',// transformer,}),],});
client/index.tstsimport {createTRPCClient ,httpLink } from '@trpc/client';import type {AppRouter } from './server';constclient =createTRPCClient <AppRouter >({links : [httpLink ({url : 'http://localhost:3000',// transformer,}),],});
httpLinkのオプション
httpLink関数はHTTPLinkOptions形式のオプションオブジェクトを受け取ります。
tsexport interfaceHTTPLinkOptions {url : string |URL ;/*** Add ponyfill for fetch*/fetch ?: typeoffetch ;/*** Data transformer* @see https://trpc.io/docs/server/data-transformers**/transformer ?:DataTransformerOptions ;/*** Headers to be set on outgoing requests or a callback that of said headers* @see https://trpc.io/docs/client/headers*/headers ?:|HTTPHeaders | ((opts : {op :Operation }) =>HTTPHeaders |Promise <HTTPHeaders >);/*** Send all requests as POSTS requests regardless of the procedure type* The server must separately allow overriding the method. See:* @see https://trpc.io/docs/rpc*/methodOverride ?: 'POST';}
tsexport interfaceHTTPLinkOptions {url : string |URL ;/*** Add ponyfill for fetch*/fetch ?: typeoffetch ;/*** Data transformer* @see https://trpc.io/docs/server/data-transformers**/transformer ?:DataTransformerOptions ;/*** Headers to be set on outgoing requests or a callback that of said headers* @see https://trpc.io/docs/client/headers*/headers ?:|HTTPHeaders | ((opts : {op :Operation }) =>HTTPHeaders |Promise <HTTPHeaders >);/*** Send all requests as POSTS requests regardless of the procedure type* The server must separately allow overriding the method. See:* @see https://trpc.io/docs/rpc*/methodOverride ?: 'POST';}
参考
このリンクのソースコードはGitHubで確認できます。