Kong / Kong/unirest-nodejs

await/async or .then options

Open
#137 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
953
Forks
164
PR merge metrics
No merged PRs in 30d

Description

I am trying to chain many unirest calls one after another where by I make decisions based on the previous rest call.

The problem is normal patterns I normally use don't work with unirest and I am trying to work out why.

what seems to happen is the .then is not respected

`await unirest.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-financials").headers({
"x-rapidapi-key": process.env.RAPITOKEN,
"x-rapidapi-host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
"useQueryString": true
}).query({
"symbol": TICKER,
"region": "US"
}).then( async (resFIN) => {

}
`

another pattern I tried is
`var something = await unirest.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-financials").headers({
"x-rapidapi-key": process.env.RAPITOKEN,
"x-rapidapi-host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
"useQueryString": true
}).query({
"symbol": TICKER,
"region": "US"
}).then( async (resFIN) => {

}`

What I get back in this situation is defined.

when I try https://stackoverflow.com/questions/39604262/returning-a-promise-from-the-unirest-client

I don't get the body back. I only get the request details made.

Is there something I am missing about unirest

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the chained unirest.get(...).query(...).then(...) example and compare it with the linked Stack Overflow pattern. Done means explaining whether await/.then returns the response body and identifying the supported chaining behavior; no repository file or test is named.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.