Enlace HTTP
Traducción Beta No Oficial
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
httpLink es un enlace terminal que envía una operación tRPC a un procedimiento tRPC mediante HTTP.
httpLink admite tanto solicitudes POST como GET.
Uso
Puedes importar y agregar httpLink al array links de la siguiente manera:
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,}),],});
Opciones de httpLink
La función httpLink recibe un objeto de opciones que sigue la estructura 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';}
Referencia
Puedes consultar el código fuente de este enlace en GitHub.