Introduction
Welcome to the documentation for ezHTTP library. ezHTTP is a versatile and easy-to-use HTTP client library for making requests and handling responses in your applications. Whether you’re building a web crawler, an API client, or just need to communicate with a remote server, ezHTTP has got you covered.
Installation
To install ezHTTP library, follow the steps below:
- Open your terminal and navigate to your project directory.
- Run the following command:
npm install ezhttp
Basic Usage
Once you have installed the library, you can start making HTTP requests in your application using ezHTTP. Here is a basic example:
import { ezHTTP } from 'ezhttp';
// Create an instance of ezHTTP
const http = new ezHTTP();
// Make a GET request
http.get('https://api.example.com/users')
.then(data => console.log(data))
.catch(err => console.error(err));
API Documentation
GET Request
Sends a GET request to the specified URL and returns a Promise that resolves to the response data.
http.get(url)
.then(data => console.log(data))
.catch(err => console.error(err));
Parameters:
- url: The URL to which the request is sent (string)
POST Request
Sends a POST request to the specified URL with the provided data and returns a Promise that resolves to the response data.
http.post(url, data)
.then(data => console.log(data))
.catch(err => console.error(err));
Parameters:
- url: The URL to which the request is sent (string)
- data: The data to send with the request (object)
PUT Request
Sends a PUT request to the specified URL with the provided data and returns a Promise that resolves to the response data.
http.put(url, data)
.then(data => console.log(data))
.catch(err => console.error(err));
Parameters:
- url: The URL to which the request is sent (string)
- data: The data to send with the request (object)
DELETE Request
Sends a DELETE request to the specified URL and returns a Promise that resolves to the response data.
http.delete(url)
.then(data => console.log(data))
.catch(err => console.error(err));
Parameters:
- url: The URL to which the request is sent (string)
Error Handling
When a request encounters an error, such as a network issue or a non-2xx HTTP status code, the corresponding Promise is rejected, and you can handle the error using the catch
method.
http.get(url)
.then(data => console.log(data))
.catch(err => console.error(err));
Conclusion
Congratulations! You have successfully learned how to use the ezHTTP library to make HTTP requests in your applications. For more advanced features and customization options, explore the library’s documentation or visit the official GitHub repository.