Skip to main content

Basic Request

Solvix provides a simple and consistent API for making HTTP requests.

This section explains how to send requests, pass data, and configure behavior.

GET Request

import { createClient } from "solvix";

const client = createClient({
baseURL: "https://jsonplaceholder.typicode.com",
});

const response = await client.get("/posts");
console.log(response.data);

Query Parameters

const response = await client.get("/posts", {
params: {
userId: 1,
},
});

Result:

/posts?userId=1

POST Request

const response = await client.post("/posts", {
title: "New Post",
body: "Hello world",
userId: 1,
});

Headers

const response = await client.get("/posts", {
headers: {
Authorization: "Bearer token",
},
});

Other Methods

PUT

await client.put("/posts/1", {
title: "Updated",
});

PATCH

await client.patch("/posts/1", {
title: "Partial Update",
});

DELETE

await client.delete("/posts/1");

Request Options

await client.get("/posts", {
timeout: 5000,
retry: { retries: 2 },
});

Base URL

const client = createClient({
baseURL: "https://api.example.com",
});

await client.get("/users");

Absolute URL

await client.get("https://api.example.com/users");

Full Example

const response = await client.post(
"/posts",
{ title: "Solvix Example" },
{
params: { preview: true },
headers: { Authorization: "Bearer token" },
retry: { retries: 2 },
},
);

console.log(response.data);

Summary

  • Supports all HTTP methods
  • Handles params, headers, body
  • Built-in retry and lifecycle handling