Wrap native HTTP requests with RFC compliant cache support
MIT License
Bot releases are hidden (Show)
Published by zzau13 about 2 years ago
Published by zzau13 about 2 years ago
Published by jaredwray about 2 years ago
Biggest change has been that when an agent is KeepAlive: true
we are now sending a response end
which will close the socket instead of an error.
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.2.0...v10.2.1
Published by jaredwray about 2 years ago
onResponse
replacing response
hookresponse
will still work but will be deprecated as we expand this functionality. onResponse
will be the name moving forward. Here are examples of how to use it.
How to decompress
import http from 'http';
import CacheableRequest from 'cacheable-request';
const cacheableRequest = new CacheableRequest(request, cache).request();
// adding a hook to decompress response
cacheableRequest.addHook('onResponse', async (value: CacheValue, response: any) => {
const buffer = await pm(gunzip)(value.body);
value.body = buffer.toString();
return value;
});
how to add a remote address
import CacheableRequest, {CacheValue} from 'cacheable-request';
const cacheableRequest = new CacheableRequest(request, cache).request();
cacheableRequest.addHook('onResponse', (value: CacheValue, response: any) => {
if (response.connection) {
value.remoteAddress = response.connection.remoteAddress;
}
return value;
});
In addition to that we have also updated some of the packages to their lates which you can read below 👇
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.1.2...v10.2.0
Published by jaredwray about 2 years ago
⚠️ Breaking Change
Based on feedback (thanks @szmarczak!) we have renamed the function createCacheableRequest
to just request
.
- const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
+ const cacheableRequest = new CacheableRequest(https.request).request();
createCacheableRequest
import CacheableRequest from 'cacheable-request';
// Now You can do
const cacheableRequest = new CacheableRequest(http.request).request();
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid
// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();
request
import CacheableRequest from 'cacheable-request';
// Now You can do
const cacheableRequest = new CacheableRequest(http.request).request();
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid
// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request).request();
const cacheableRequest = new CacheableRequest(electron.net).request();
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.2...v10.1.2
Published by jaredwray about 2 years ago
Change to support got
by exporting types enabling better integration with upstream packages.
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.1...v10.0.2
Published by jaredwray about 2 years ago
Minor maintenance release with some primary packages updated such as:
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.0...v10.0.1
Published by jaredwray about 2 years ago
This release contains breaking changes as we are now using class
to handle instances and hooks better. This is the new way to use this package.
import http from 'http';
import CacheableRequest from 'cacheable-request';
// Then instead of
const req = http.request('http://example.com', cb);
req.end();
// You can do
const cacheableRequest = new CacheableRequest(http.request);
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid
// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request);
const cacheableRequest = new CacheableRequest(electron.net);
import CacheableRequest from 'cacheable-request';
// Now You can do
const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid
// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();
The biggest change is that when you do a new
CacheableRequest you now want to call createCacheableRequest
method will give you the instance to use.
- const cacheableRequest = new CacheableRequest(http.request);
+ const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v9.0.0...v10.0.0
Published by jaredwray about 2 years ago
cacheable-request
is now pure ESM with version v9.0.0
and up. Version v.8.x.x
is the supported commonjs version which will get only major security fixes moving forward until end of 2022. If you would like to learn about uprgrading / using ESM @sindresorhus has an amazing reference guide here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
Major thank you to @alphmth, @sindresorhus, @szmarczak, @jasonbaik, and everybody for help on this. 🙌
Special call out to @CyberShadow as in the previous release we forgot to mention the work done on issue #28 as without their guidance and code we wouldn't have fixed it. ❤️
In addition to pure ESM we are now fulling using Typescript moving forward on this project which means all type definitions are now native with the service. 🤩
Hooks have been introduced for the response
object that will run a processing function like so if you wanted to do compression:
CacheableRequest.addHook('response', async (response: any) => {
const buffer = await pm(gunzip)(response);
return buffer.toString();
});
const cacheableRequest = CacheableRequest(request, cache);
How to Add a Hook: https://github.com/jaredwray/cacheable-request#add-hooks
How to Remove a Hook: https://github.com/jaredwray/cacheable-request#remove-hooks
We would love some feedback on this feature!
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v8.3.1...v9.0.0
Published by jaredwray over 2 years ago
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v8.0.1...v8.3.1
Published by jaredwray over 2 years ago
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v8.0.0...v8.0.1
Published by jaredwray over 2 years ago
Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v7.0.2...v8.0.0