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 { createTRPCProxyClient, httpLink } from '@trpc/client';import type { AppRouter } from '../server';const client = createTRPCProxyClient<AppRouter>({links: [httpLink({url: 'http://localhost:3000',}),],});
client/index.tstsimport { createTRPCProxyClient, httpLink } from '@trpc/client';import type { AppRouter } from '../server';const client = createTRPCProxyClient<AppRouter>({links: [httpLink({url: 'http://localhost:3000',}),],});
Opciones de httpLink
La función httpLink recibe un objeto de opciones que sigue la estructura HTTPLinkOptions.
tsexport interface HTTPLinkOptions {url: string;/*** Add ponyfill for fetch*/fetch?: typeof fetch;/*** Add ponyfill for AbortController*/AbortController?: typeof AbortController | null;/*** Headers to be set on outgoing requests or a callback that of said headers* @see http://trpc.io/docs/v10/header*/headers?:| HTTPHeaders| ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);}
tsexport interface HTTPLinkOptions {url: string;/*** Add ponyfill for fetch*/fetch?: typeof fetch;/*** Add ponyfill for AbortController*/AbortController?: typeof AbortController | null;/*** Headers to be set on outgoing requests or a callback that of said headers* @see http://trpc.io/docs/v10/header*/headers?:| HTTPHeaders| ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);}
Referencia
Puedes consultar el código fuente de este enlace en GitHub.