Last active
December 2, 2019 07:49
-
-
Save suejungshin/6579bf9da7b10fb0646035198beb5dea to your computer and use it in GitHub Desktop.
Sample API call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client side | |
getAnalystRatings () { | |
$.ajax({ | |
method: 'GET', | |
url: 'http://localhost:3000/analystRatings', | |
success: (data) => { | |
this.setState( | |
{analystRatings: data} | |
) | |
console.log('Get request successful: ', data); | |
} | |
}) | |
} | |
// Server side | |
app.get('/analystRatings', (req, res) => { | |
// Send GET request for a single user using query parameter STOCK TICKER | |
let result = queryDatabase(req.query); | |
res.send('Analyst Rating Data from my database here: ', result) | |
}) | |
// sample JSON output | |
// continues for 100 records | |
[{ | |
"ticker": "COF.WS", | |
"companyName": "Capital One Financial Corporation", | |
"rating_cnt_buys": 5, | |
"rating_cnt_holds": 29, | |
"rating_cnt_sells": 14 | |
}, { | |
"ticker": "TOO^A", | |
"companyName": "Teekay Offshore Partners L.P.", | |
"rating_cnt_buys": 30, | |
"rating_cnt_holds": 10, | |
"rating_cnt_sells": 29 | |
}, { | |
"ticker": "WFC^R", | |
"companyName": "Wells Fargo & Company", | |
"rating_cnt_buys": 15, | |
"rating_cnt_holds": 27, | |
"rating_cnt_sells": 19 | |
}, { | |
"ticker": "ABR^C", | |
"companyName": "Arbor Realty Trust", | |
"rating_cnt_buys": 26, | |
"rating_cnt_holds": 27, | |
"rating_cnt_sells": 24 | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment