Initialize a 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("");
To create an HTTP client, just use the createHttpClient function from @duplojs/http/clients.
To fully type the client, pass a ServerRoute-typed object as a generic.
TIP
To generate the full typing for an @duplojs/http server, use the code-generator plugin.
