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에서 확인할 수 있습니다.