Skip to content

Make a request

ts
import { 
createHttpClient
} from "@duplojs/http/client";
import { type
Routes
} from "./types";
const
client
=
createHttpClient
<
Routes
>({
baseUrl
: "http://localhost:1506",
}); const
promiseRequestCreateUser
=
client
.
post
(
"/users", {
body
: {
username
: "math",
age
: 23,
}, }, ); // select good path const
promiseRequest
=
client
.
post
("
");
// and good params const
promiseRequestFindManyPost
=
client
.
get
(
"/posts", {
query
: {
page
: "3" } },
);

To make a request, just call the get, post, patch, put, delete, or request methods on the HTTP client. These methods return a PromiseRequest, which is an object that extends Promise.

If you initialized your client with typing, it will suggest the available paths and parameters for each route. No more mistakes!

Released under the MIT License.