v2.0.0-rc.1
Pre-releaseChangelog
Version 2.0.0-rc.1
This is a major update that includes breaking changes and significant improvements to the HTTP client library.
Breaking Changes
-
Removed dependency on
gotlibrary- The HTTP client now uses the native
fetchAPI instead ofgot. - This change may affect how requests are made and how responses are handled.
- The HTTP client now uses the native
-
Updated
prom-clientto be a peer dependency- You now need to install
prom-clientseparately if you want to use metrics.
- You now need to install
-
Removed
@types/gotand@types/url-templatedependencies- These are no longer needed due to the removal of
gotand the update tourl-template.
- These are no longer needed due to the removal of
-
Updated minimum Node.js version
- The library now requires a Node.js version that supports native
fetch.
- The library now requires a Node.js version that supports native
-
Changed the
requestmethod signature- The method now returns a
Promise<Result>instead of the previous return type.
- The method now returns a
-
Changed the
options type
- The method now takes options that are entirely different to the previous
GotOptions - Timeout that now needs to be passed in with it's own AbortController
New Features
-
Native
fetchAPI support- This provides better compatibility with modern JavaScript environments (v22).
-
Improved TypeScript support
- Updated to TypeScript 5.7.2 for better type inference and stricter checks.
-
ESLint integration
- Replaced TSLint with ESLint for better code quality checks.
Dependency Updates
- Upgraded
url-templateto version 3.1.1 - Removed
gotdependency - Updated dev dependencies to their latest versions
How to Upgrade
- Update your package.json:
{
"dependencies": {
"@loke/http-client": "^2.0.0",
"prom-client": "^12.0.0" // or later
}
}-
If you were using
got-specific features, you'll need to refactor your code to use the newfetch-based API. -
Update your imports if you were directly using any of the removed dependencies.
-
Review and update your usage of the
requestmethod to handle the newResulttype. -
Run your tests and check for any breaking changes in your application.
Code Migration Examples
Before:
import { HTTPClient } from '@loke/http-client';
const client = new HTTPClient({ baseUrl: 'https://api.example.com' });
const response = await client.request('GET', '/users/{id}', { id: 123 });
console.log(response.body);After:
import { HTTPClient } from '@loke/http-client';
const client = new HTTPClient({ baseUrl: 'https://api.example.com' });
const result = await client.request('GET', '/users/{id}', { id: 123 });
console.log(result.body);Note: The result object now has a different structure. Make sure to check the statusCode and handle the body appropriately.
If you encounter any issues during the upgrade process, please refer to the detailed documentation or open an issue on the project's repository.