Quick Start
You can use the default instance of boltfetch directly for simple requests without any configuration.
Basic GET Request
typescriptimport { boltfetch } from "boltfetch"; async function fetchUser() { // Pass the expected return type as a generic const response = await boltfetch.get<{ id: number; name: string }>( "https://api.github.com/users/himanshupadecha" ); if (response.success) { // response.data is strongly typed console.log("User Data:", response.data.name); } else { // response.message explains what went wrong console.error("Error:", response.message); } } fetchUser();
Basic POST Request
When you pass data as the second argument to post, put, or patch, BoltFetch automatically serializes it to JSON and sets the appropriate Content-Type header.
typescriptimport { boltfetch } from "boltfetch"; async function createPost() { const newPost = { title: "Hello", content: "World" }; const response = await boltfetch.post<Post>("/api/posts", newPost); if (response.success) { console.log("Post created with ID:", response.data.id); } }
Basic Configuration
If you need to pass headers or query parameters, provide them in the final config argument.
typescriptimport { boltfetch } from "boltfetch"; async function searchUsers(query: string) { const response = await boltfetch.get("/api/users", { headers: { "Authorization": "Bearer my_token" }, params: { search: query, limit: 10 } // Automatically appends ?search=query&limit=10 }); }
If you find yourself passing the same headers or base URLs repeatedly, it's time to check out the Configuration section to create a custom client instance using configureBoltFetchClient!