Lien HTTP
Traduction Bêta Non Officielle
Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →
httpLink est un lien terminal qui envoie une opération tRPC à une procédure tRPC via HTTP.
httpLink prend en charge les requêtes POST et GET.
Utilisation
Vous pouvez importer et ajouter le httpLink au tableau links comme suit :
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',}),],});
Options de httpLink
La fonction httpLink accepte un objet d'options conforme au type 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>);}
Référence
Vous pouvez consulter le code source de ce lien sur GitHub.