This library is a simple and efficient HTTP client for making API calls in TypeScript applications. It provides a clean API for sending HTTP requests and handling responses.
- Easy to use: A simple interface for making HTTP requests.
- Type safety: Built with TypeScript to ensure type safety in request and response handling.
- Supports various HTTP methods: GET, POST, PUT, DELETE, etc.
- Customizable request headers: Set custom headers for your requests.
- Error handling: Built-in error handling for easy debugging.
- Promise-based API: Supports asynchronous requests using Promises.
To install this library, run:
npm install ts-http-clientimport { HttpClient } from 'ts-http-client';
const client = new HttpClient();
client.get('https://api.example.com/data').then(response => {
console.log(response.data);
}).catch(error => {
console.error('Error fetching data:', error);
});import { HttpClient } from 'ts-http-client';
const client = new HttpClient();
const data = { key: 'value' };
const headers = { 'Authorization': 'Bearer token' };
client.post('https://api.example.com/submit', data, { headers }).then(response => {
console.log('Data submitted:', response.data);
}).catch(error => {
console.error('Error submitting data:', error);
});get(url: string, options?: RequestOptions): Promise<Response>- Sends a GET request.post(url: string, data: any, options?: RequestOptions): Promise<Response>- Sends a POST request.put(url: string, data: any, options?: RequestOptions): Promise<Response>- Sends a PUT request.delete(url: string, options?: RequestOptions): Promise<Response>- Sends a DELETE request.
headers?: Record<string, string>- Custom headers for the request.timeout?: number- Request timeout in milliseconds.
data: any- The response data.status: number- The HTTP status code.statusText: string- The status message.
- Clone the repository:
git clone https://github.com/abdul-kasif/ts-http-client.git
- Install dependencies:
npm install
- Run the development server:
npm start
- Run tests:
npm test - Create your feature branches and submit pull requests for changes.
This project is licensed under the MIT License - see the LICENSE file for details.