Grab.js is a minimalistic HTTP client designed to make web requests simple and efficient. At just 5KB, it offers a range of features like circuit breakers, ETags, and request deduplication, making it suitable for both small projects and larger applications.
For the latest updates and releases, visit the Releases section.
You can install Grab.js via npm. Run the following command in your terminal:
npm install grab-js
For a more manual approach, you can download the latest release from the Releases section and execute the file.
Using Grab.js is straightforward. Below is a simple example of how to make a GET request:
import Grab from 'grab-js';
const client = new Grab();
client.get('https://api.example.com/data')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error fetching data:', error);
});
To make a POST request, you can use the post
method:
client.post('https://api.example.com/data', {
key: 'value'
})
.then(response => {
console.log('Data saved:', response.data);
})
.catch(error => {
console.error('Error saving data:', error);
});
You can use the circuit breaker feature to prevent your application from sending requests to an unresponsive server:
client.setCircuitBreaker(true);
client.get('https://api.example.com/data')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Request failed, circuit breaker activated:', error);
});
Using ETags helps to cache responses efficiently:
client.get('https://api.example.com/data', { headers: { 'If-None-Match': 'your-etag-here' } })
.then(response => {
if (response.status === 304) {
console.log('Data has not changed.');
} else {
console.log('Fetched new data:', response.data);
}
})
.catch(error => {
console.error('Error fetching data:', error);
});
We welcome contributions to Grab.js! To contribute, please follow these steps:
git checkout -b feature/YourFeature
).git commit -m 'Add some feature'
).git push origin feature/YourFeature
).Grab.js is licensed under the MIT License. See the LICENSE file for more details.
For the latest updates and releases, visit the Releases section.