score:0

Accepted answer

in this specific case, where a token is needed to fetch data at backend, i found that passing token at url is more suitable, like so:

@endpoint.route('/endpoint/<select>/<user_id>/<token>', methods=['get'])
def endpoint(name, user_id, token):
# business logic

and:

const options = {
  url: `${process.env.react_app_web_service_url}/endpoint/${select}/${userid}/${this.props.spotifytoken}`,
  method: 'get',
  headers: {
    'content-type': 'application/json',
    authorization: `bearer ${window.localstorage.authtoken}`
  }
};

otherwise, backend code would run twice, for post and get, which is not desired in my case.

score:0

for an async await applied to your code would look something like this.

async getdata(event) {
  const {token} = this.props.spotifytoken

  let getres = await axios.get(`${process.env.url}/endpoint` {
    headers: {
      'content-type': 'application/json',
      'authorization': `bearer ${window.localstorage.authtoken}`
    }
  }

  let postres = await axios.post(`${process.env.url}/endpoint` {
    headers: {
      'content-type': 'application/json',
      'authorization': `bearer ${window.localstorage.authtoken}`
    }
  }

  console.log(getres.data.data);
  console.log(postres.data.data);
};


Related Query

More Query from same tag