What is @gitbeaker/requester-utils?
@gitbeaker/requester-utils is a utility package designed to facilitate HTTP requests, particularly in the context of interacting with GitLab's API. It provides a set of tools to simplify the process of making authenticated requests, handling responses, and managing configurations.
What are @gitbeaker/requester-utils's main functionalities?
Authenticated Requests
This feature allows you to create a requester function that automatically includes authentication headers in your HTTP requests. The code sample demonstrates how to create a requester and make a GET request to fetch projects.
const { createRequesterFn } = require('@gitbeaker/requester-utils');
const requester = createRequesterFn({
host: 'https://gitlab.example.com',
token: 'your_access_token',
});
requester.get('/projects')
.then(response => console.log(response))
.catch(error => console.error(error));
Custom Request Configurations
This feature allows you to customize various request configurations such as timeout settings. The code sample shows how to set a custom request timeout.
const { createRequesterFn } = require('@gitbeaker/requester-utils');
const requester = createRequesterFn({
host: 'https://gitlab.example.com',
token: 'your_access_token',
requestTimeout: 5000,
});
requester.get('/projects')
.then(response => console.log(response))
.catch(error => console.error(error));
Handling Responses
This feature provides a way to handle responses and errors effectively. The code sample demonstrates how to check the response status and handle errors.
const { createRequesterFn } = require('@gitbeaker/requester-utils');
const requester = createRequesterFn({
host: 'https://gitlab.example.com',
token: 'your_access_token',
});
requester.get('/projects')
.then(response => {
if (response.status === 200) {
console.log('Projects:', response.data);
} else {
console.error('Error:', response.statusText);
}
})
.catch(error => console.error('Request failed:', error));
Other packages similar to @gitbeaker/requester-utils
axios
Axios is a popular promise-based HTTP client for the browser and Node.js. It provides similar functionalities such as making HTTP requests, handling responses, and managing configurations. Compared to @gitbeaker/requester-utils, Axios is more general-purpose and widely used across various projects.
node-fetch
Node-fetch is a lightweight module that brings `window.fetch` to Node.js. It is used for making HTTP requests and handling responses. While it offers similar functionalities, it is more minimalistic compared to @gitbeaker/requester-utils, which is tailored for GitLab API interactions.
request
Request is a simplified HTTP client for Node.js with a user-friendly API. It provides functionalities for making HTTP requests and handling responses. Although it is similar in purpose, it is more feature-rich and flexible compared to @gitbeaker/requester-utils.
40.1.0 (Mon Jul 08 2024)
:tada: This release contains work from new contributors! :tada:
Thanks for all your work!
:heart: null@YupaTT
:heart: null@nhollander-alert
:heart: Ali Souidan (@ali-souidan)
:heart: null@omer-rivlin-platinum
:heart: null@michael-smt
:heart: Sefa Eyeoglu (@Scrumplex)
✨ Feature
@gitbeaker/requester-utils
, @gitbeaker/rest
- Remove token requirement to support access without authentication #3588 (@michael-smt)
@gitbeaker/core
, @gitbeaker/rest
🐛 Bug Fix
@gitbeaker/core
- Epic label events super used singular 'epic', not 'epics' #3594 (@arsdehnel)
🚑 Hot Fix
@gitbeaker/cli
, @gitbeaker/core
, @gitbeaker/requester-utils
, @gitbeaker/rest
🔨 Technical Debt
↕️ Dependencies
🗃️ Typescript Definitions
⚠️ Pushed to main
@gitbeaker/cli
, @gitbeaker/core
, @gitbeaker/requester-utils
, @gitbeaker/rest
🚨 Tests
📚 Documentation
Authors: 9