3 ms·
Show HN: Simplifying http requests using ES decorators
- Etheryte 10y agoNot sure if I see how this is any different from simply using `<a library of your choice>.get(...)`. Just a different, imho more confusing, syntax.
- jblaak 10y agoFor single requests this would, indeed, be the best solution. However, when exposing an interface to multiple endpoints, requiring the same base url, pre/post-processing of requests this helped me quite a bit.
- davej 10y agoI'm having trouble figuring out how this would look in code and how it would be more graceful than async/await. Can you share an example?
- jblaak 10y agoSure! Here is a gist: https://gist.github.com/JBlaak/8d9fdebb2a28a0b9026a71bced7cceaf https://gist.github.com/JBlaak/8d9fdebb2a28a0b9026a71bced7cc... Every request will have the `accept` and `X-Requested-With` headers and prefixed with some route prefix using the request and the base decorators. As you can see in consumer.js you use async/await to consume results generated by the methods.