Skip to content

Initialiser un client

ts
import { 
createHttpClient
} from "@duplojs/http/client";
export type
Routes
= {
method
: "GET";
path
: "/hello-world";
query
: {
name
: string;
};
responses
: {
code
: "422";
information
: "extract-error";
body
?: undefined;
} | {
code
: "200";
information
: "helloWorld.send";
body
: string;
}; }; const
client
=
createHttpClient
<
Routes
>({
baseUrl
: "http://localhost:1506",
}); // autocomplete arguments await
client
.
get
("
");

Pour créer un client HTTP, il vous suffit d'utiliser la fonction createHttpClient de @duplojs/http/clients.

Pour typer entièrement le client, il vous suffit de passer en générique un objet du type de ServerRoute.

TIP

Pour générer l'entièreté du typage d'un serveur @duplojs/http, il vous suffit d'utiliser le plugin code-generator.

Diffusé sous licence MIT.