Comments (11)
this issue was actually raised from another company too, they could not use unirest-node bcz of no cache.
from unirest-nodejs.
Thanks. Our current stop-gap solution is to call unirest, but wrap every call in a special handler to decide whether to make the call, cache the response, etc. Some built-in support would be amazing.
from unirest-nodejs.
This is not something that is within the scope of the library, this should be done outside of the library (a plugin would be fine, separate repo).
from unirest-nodejs.
Thanks. Our current stop-gap solution is to call unirest, but wrap every call in a special handler to decide whether to make the call, cache the response, etc. Some built-in support would be amazing.
This is the correct way to do it, as it is a per case basis, not everyone will have the same requirements or situation as yours.
Hence why being a plugin would be a better solution for this situation.
from unirest-nodejs.
Fair point @nijikokun. About a "plugin", I can imagine two different approaches:
- we have to wrap unirest
This is pretty much what we currently do, but it quite painful to implement if you want caching across the board. If we want an easy drop-in solution, we could create a library that wraps unirest
to support typical caching/proxy concerns. On the downside it would have to delegate the entire unirest API. For example, in the end
function below, the proxy would check if that request is in cache, call unirest
if it's not, and cache the response on the way back before calling the callback.
var proxy = new InMemoryProxy();
proxy.get('http://awesome/api')
.set('Accept', 'application/json')
.end(function(res) {});
- pluggable plugin support
This would let unirest
take an optional reverse proxy to pass every request/response through. The proxy receives every Request
object on the way out, and can optionally cancel them (e.g. if it was returned from cache), and gets every Response
object on the way in as well.
unirest.get('http://awesome/api')
.set('Accept', 'application/json')
.through(myProxy)
.end(function(res) {});
from unirest-nodejs.
Also minor comment on not everyone will have the same requirements or situation as yours
, I wouldn't think these are crazy requirements. We're talking about caching, which is one of the fundamental pillars of the web, and has well defined standards across browsers, reverse proxies, etc... But agreed that a plugin of some sort would make sure people can handle any type of requirements they have 😃
from unirest-nodejs.
Plugins could be hooked like middleware, global plugins, and local plugins,
I like the .through but maybe it could be .plugin
On Wed, Feb 11, 2015 at 4:39 PM, Romain Prieto [email protected]
wrote:
Fair point @nijikokun https://github.com/Nijikokun. About a "plugin", I
can imagine two different approaches:
- we have to wrap unirest
This is pretty much what we currently do, but it quite painful to
implement if you want caching across the board. If we want an easy drop-in
solution, we could create a library that wraps unirest to support typical
caching/proxy concerns. On the downside it would have to delegate the
entire unirest API. For example, in the end function below, the proxy
would check if that request is in cache, call unirest if it's not, and
cache the response on the way back before calling the callback.var proxy = new InMemoryProxy();
proxy.get('http://awesome/api')
.set('Accept', 'application/json')
.end(function(res) {});
- pluggable plugin support
This would let unirest take an optional reverse proxy to pass every
request/response through. The proxy receives every Request object on the
way out, and can optionally cancel them (e.g. if it was returned from
cache), and gets every Response object on the way in as well.unirest.get('http://awesome/api')
.set('Accept', 'application/json')
.through(myProxy)
.end(function(res) {});—
Reply to this email directly or view it on GitHub
#47 (comment)
.
from unirest-nodejs.
👍 on plugin, which could be as simple as plugin.request(request)
that returns true if the plugin handled it, and plugin.response(response)
just before calling the end
callback.
from unirest-nodejs.
Closing since this was agreed to be a plugin
from unirest-nodejs.
Hi @Nijikikun, I'm happy to help write the plugin... is there a plugin interface / system already? I thought that was the current blocker (e.g. no request.get('/foo').plugin(bar).send()
). Given plugins are likely to want to inspect/manipulate both requests and responses, something similar to Connect/Koa middleware would be great.
from unirest-nodejs.
I think I will open an issue to address perhaps a plugin specification, that way we can come up with something, I haven't had time to think about as of right now. Working on a new release with all these backlogged items
from unirest-nodejs.
Related Issues (20)
- npm audit failure HOT 3
- How to save/re-use cookies from file? HOT 2
- Is it possible to upload (attach) file/image as base64 HOT 1
- Maintainers? HOT 2
- version of unirest of kong need upgrade HOT 1
- Passing a Buffer to .attach HOT 5
- TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Length" HOT 5
- header type check bug
- Set specific agent per request
- Uploading file with metadata using unirest js api causing trouble when sending data
- Request.part()
- Does this library support async / await or not?
- http://unirest.io/nodejs doesn't work HOT 1
- await/async or .then options
- Setting .strictSSL(false) does not work for .attach() HOT 1
- Unirest is running asynchronously
- Potential security issue
- Problem sending files via HTTP request for TestRail.
- Still maintained?
- unirest is not working for node 12.x
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unirest-nodejs.