WDI-SEA / project-2-issues

0 stars 0 forks source link

authorization header #19

Closed paulinal3 closed 2 years ago

paulinal3 commented 2 years ago

The other API I'm using says it "requires a token to be sent in as an authorization header" Exact format for sending token:

{ authorization: Token_<token goes here> }

And the docs don't show anything about adding the token at the end of the api url so where would I put the authorization header? Does it go before every axios call or at the top of the page? I have the token already saved in my .env

The code below is what I've tried but nodemon keeps spitting out a really long chunk of code and ending with saying [nodemon] app crashed - waiting for file changes before starting...

router.get('/results', (req, res) => {
    {authorization: process.env.API_KEY}
    const rootApi = 'https://v1.exercisedb.io/api/exercises'
    let muscleTargeted = req.query.bodyPart

    axios.get(`${rootApi}/bodyPart/${muscleTargeted}`)
    .then(apiRes => {
        console.log('this is the apiRes', apiRes.data)
    })
})

Also wondering if someone can just take a look at my ERD a second time to make sure it makes sense.

tkolsrud commented 2 years ago

Here's sample of the syntax: https://www.codegrepper.com/code-examples/javascript/axios+post+request+send+bearer+token

tkolsrud commented 2 years ago

You've got the right idea, you just need to put that authorization object in the axios.get after the url

paulinal3 commented 2 years ago

Oh my bad!! Sorry I was able to figure that part out! Now I only need someone to talk through my ERD to make sure it's right before I start creating models

tkolsrud commented 2 years ago

Oh good! Why don't you open a new request with a screenshot of the erd that way everyone can get eyes on it