request-caller
v0.1.12
Published
A simple request caller for your web project using axios
Downloads
3
Readme
Axios HTTP Request Caller
Overview
This TypeScript project provides a convenient interface for making HTTP requests using the Axios library. It simplifies the process of performing GET
, POST
, PUT
, PATCH
, and DELETE
requests by encapsulating common functionality and providing a clean API.
Installation
To use this library in your TypeScript project, follow these steps:
- Install the Axios HTTP Request Caller library:
npm install request-caller
Usage
Import the API class and use its static methods for making HTTP requests. Here's an example of how to use the library:
import { API } from 'request-caller';
interface User {
id: number;
name: string;
email: string;
}
// GET
const userList = await API.get<User[]>({
url: '/users',
queryParams: {
limit: 10,
page: 1,
},
});
// POST
const userCreated = await API.post<User>({
url: '/users',
headers: {
'Content-type': 'application/json',
},
body: {
name: 'John Doe',
email: '[email protected]',
},
});
// PUT
const userUpdated = await API.put<User>({
url: '/users/1',
body: {
name: 'John Doe',
email: '[email protected]',
},
});
// PATCH
const userPatched = await API.patch<User>({
url: '/users/1',
body: {
name: 'John Dow',
},
});
// DELETE
const userDeleted = await API.delete<User>({
url: '/users/1',
});
API Methods
get<T>(config: GetResquestConfig): Promise<T>
Perform a GET request.
post<T>(config: PostResquestConfig): Promise<T>
Perform a POST request.
put<T>(config: PutResquestConfig): Promise<T>
Perform a PUT request.
patch<T>(config: PatchResquestConfig): Promise<T>
Perform a PATCH request.
delete<T>(config: DeleteResquestConfig): Promise<T>
Perform a DELETE request.`
Request Configuration
url
: The URL for the HTTP request.
headers
: (Optional) Custom headers for the request.
queryParams
: (Optional) Query parameters for the request.
body
: (Optional) Request payload for POST, PUT, PATCH requests.
Contributing
Contributions are welcome! Please follow the contribution guidelines when submitting pull requests.
License
This project is licensed under the MIT License.