HTTP Requests#
HTTP utility is in src/lib/http.ts.
Auto Headers#
Every request automatically includes:
cssAuthorization: Bearer {localStorage.token}
Content-Type: application/json
Usage#
typescriptimport { http } from "@/lib/http"
// GET
const res = await http.get<User>("/v1/users/info")
// POST
const res = await http.post<Todo>("/v1/todos", { title: "Hello" })
// PUT
const res = await http.put<Todo>("/v1/todos", { id: "...", title: "Updated" })
// DELETE
const res = await http.delete("/v1/todos")
Response Format#
All endpoints return a unified format:
typescriptinterface ApiResponse<T> {
success: boolean
message: string
data: T
}
Error Handling#
When success === false, a toast error is shown automatically (Sonner).
Use silent to suppress:
typescriptconst res = await http.get("/v1/some-api", { silent: true })
if (!res.success) {
// Handle error manually
}
401 Auto-Handling#
On 401 response, the token is cleared and the user is redirected to /signin.