I am trying to wire up my app to an external API. The external API's documentation says to make the call using curl:
curl "https://wordsapiv1.p.mashape.com/words/soliloquy"
-H "X-Mashape-Key: <required>"
My app is built with JS/React - I am unfamiliar with the above syntax. I am trying to figure out how to write this using superagent (or, if necessary, fetch).
This is what I have so far from following some other Stack Overflow answers but I have no idea how to incorporate: -H "X-Mashape-Key: <required>"
My API key is stored in a .env file.
require('dotenv').config
console.log(process.env)
const request = require('superagent')
const url = 'https://wordsapiv1.p.mashape.com/words/'
//dictionary
export function getDictionaryDefinition(word) {
return request.get(`${url}/dog`).then((response) => {
console.log(response)
})
}
I highly recommend getting familiar with the basics of
curl. It's worth knowing and it's everywhere. you can find nice cheat sheets here and here.-Hincurlrepresent a header, so in your case you'll need to add that to your request, e.g.or in fetch:
as a bonus, I found a nice project that "translates"
curltofetch: https://kigiri.github.io/fetch/