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);
};
Source: stackoverflow.com
Related Query
- React - GET and POST requests with axios
- react native post form data with object and file in it using axios
- React and Axios GET request issue with Safari on MacOs and iOs
- React - Axios POST form data with files and strings
- how do I make a post and get request with ReactJS, Axios and Mailchimp?
- React POST requests with Express/Node and MongoDB
- how to get images from mongo with axios and display them with react
- REACT How to make AJAX requests with Redux and Axios (with promise middleware)?
- Correct way to React axios post with UUID and nested object in JSON payload?
- Getting status code 304 on a get request with axios using react and redux
- Post Data With Redux and Fetch API with Axios Get Error Result so Looping Response Pending
- How to make POST request with axios and React State Hook
- Unit Testing with Jest and React - Axios Get Inside useEffect
- Create temp file and get file with axios in React and show download pop up
- react get data from rest api with axios and and useEffect redering empty array plus array with data
- how to get spesific data from api with axios and react js?
- Dealing with post requests and tokens while testing a React application with Jest
- how to write one GET api call using axios instance with and without params in React JS
- Can't send a post request through Axios and Nodemailer with React and Node.js - in dev mode
- Get values from form with React and Axios
- How to check email overlap using Axios get and post for SignUp with React?
- How to perform a post request with axios on React and pass your data as FormData?
- React and Socket.io: Able to get initial data - but view doesn't update when a new post comes in
- How to send body data and headers with axios get request?
- react dropzone cannot post with axios
- react with Rails 5, getting CSRF error for post with axios
- Using different API url for development and production with React and axios
- Post an object with fetch using react js and express API server
- In Visual Studio 2012, I get warnings and squiggly lines when trying to write JSX with React JS
- Forbidden (CSRF cookie not set.) with React and axios
More Query from same tag
- React Navigation - Gradient color for Header
- Error while using antd components in react
- I Want To Display The ImagesUrl's In The Array according To The Number of images the Array has, using Reactjs
- How to call a function from Props interface in Typescript/React
- How to sort and filter in reactjs redux
- How to redirect to a new page in react and typescript after an animation
- How to fetch data from a JSON file?
- React diplay objects that have lists within them
- How do I access nested object properties within React props
- Heroku - Seperate frontend and backend with Nginx on same domain
- How to use the key (defined from lists items key) as prop on my Modal
- NextJS: getStaticProps revalidate not working
- Uncaught TypeError: Cannot read properties of undefined (reading 'roll')
- I need to pass a variable from one component to another
- ReactJS: Dynamically add a component on click
- React Virtualized Table - performance issues with input element in ~8 columns table
- How to fix this Jest error: "component encountered a declaration exception"?
- Export default failed in JSX with babel
- Typescript String enum type 'string' is not assignable to type
- .velocity is not a function
- In NextJs, After logout, when I open dashboard direct url it open and after checking auth it redirect to login page very slow?
- How to create a dynamic grid in react.js?
- How map throw forEach() inside the filter() in ReactJs
- Errors on 'concurrently "npm run server" "npm run client" with MERN
- How can I select a specific part in my svg imported with ReactComponent as Logo?
- Still getting "React state update on an unmounted component" error with React Testing Library tests
- Rect doesn't visualized after append
- Object is not extensible error when creating new attribute for array of objects
- Render async component in React Router v4
- @aws-amplify/ui-react how to customize UI if my project uses SASS?