Node frameworks usually work via (err, result)
callbacks.
Is there a promise-based http framework for Node, with a healthy community and in active development (such as express)?
A promise-based client returns promises rather than accepting callbacks. Follow this answer to receive notifications.
A Promise in Node means an action which will either be completed or rejected. In case of completion, the promise is kept and otherwise, the promise is broken. So as the word suggests either the promise is kept or it is broken. And unlike callbacks, promises can be chained.
Axios is a promised-based HTTP client for JavaScript. It has the ability to make HTTP requests from the browser and handle the transformation of request and response data.
A Node. js Promise is a placeholder for a value that will be available in the future, allowing us to handle the result of an asynchronous task once it has completed or encountered an error. Promises make writing asynchronous code easier. They're an improvement on the callback pattern and very popular in Node.
There is https://github.com/mzabriskie/axios
Promise based HTTP client for the browser and node.js
Example code:
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
I had the same question you had today, and I found q-io, also by kriskowal. It uses Q.js to promise-wrap filesystem io as well as server and http client.
I have not tried it out yet, but it definitely does not seem to have an active community built around it at this point. Sad thing to see, in a world filled with callback pyramids of doom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With