score:0
you want to take the date state from your client and send it to your api endpoint through a post request. your api endpoint will then take the date from the req.body and insert that into it's own request to the nasa api. your api will await the nasa api's response and send that back to the client once it is received.
client
await axios({
method: "post",
url: "yourapi/customdate",
data: {
date: this.state.date
},
withcredentials: false
}).then((response) => {
//response from your api that includes the nasa api image
})
server
router.post("/customdate", async (req, res) => {
const customdate = req.body.date
await axios({
method: "get",
url: `https://api.nasa.gov/planetary/apod?api_key=${process.env.react_app_api_key_nasa}&date=${customdate}`,
withcredentials: false
}).then((response) => {
res.send(response.image)
})
})
score:1
you should have one more axios call from the react to your nodejs as react(front-end) and nodejs(back-end) will be two different things.
it is either you call directly from react to nasa api (which will exposed your api key in the front-end) or react axios call to your nodejs and then nodejs axios call (api key) to nasa api.
Source: stackoverflow.com
Related Query
- How do I pass data from react front end to node express backend?
- What should I use to make API requests to my node back end from my React front end?
- How to send form data from React to the Node JS back end server
- How to pass data from React front end Hooks to Express backend
- React Microfronends: How do I pass authentication and other information from one Front end app to another Front end app?
- How do I send data from React to Node server and back result to React?
- Data from my react front end not getting to mysql database
- Pass Data from React to node express server
- React front end connects to the development server on my computer instead of the Node server on Azure VM where it is hosted from why using localhost
- Redirect and send data from Node server back to React
- Send data back to React client from Node server with POST request
- Allowing CORS from React front end not allowing Express back end to use Bing API
- Fetching param.id data from front to backend - React / Node / Express
- Sending Express back-end data from a database to React front end
- Best way to pass data back from class to react component?
- How do I pass in objectId from the react front end to server-side graphql?
- React pass data from front-end to back-end node
- Unable to pass Date object to back end from React to Spring Boot
- Node application interactively get user input from react front end by pausing the current execution
- Sending data back from node server back to react frontend
- Get data from Node endpoint and pass into React frontend
- How can I fetch data from mongoDB and display it on react front end
- Why my react front end does not want to download my file sent from my express back end?
- How to pass data from React form to Node code?
- I want to pass data from flask back to React and render html based on it
- how to honor windows use from React js front end application when node js api is used
- How to pass a data from Node js to React or redirect a page from the sever
- access data from a rails service in react front end react-on-rails
- Is there a right way to pass data into a React component from the HTML page?
- How can I pass data from express server to react views?
More Query from same tag
- How to highlight React tsx with PrismJS
- How can you combine multiple async file uploads and be able to reference and write BOTH newly created URLS to database at same time?
- React: Filter multidimensional array object by value in component
- Can't figure out how to style rc-slider (React Component Slider) via inline styling
- How would I animate the width of a button based on percentage, and the same for it's backgroundColor?
- Resize an image, before uploading to Firebase Storage using Javascript
- Why is flex container wrapper the flex items despite exceeding 100%?
- React Hooks - useState using the result of another hook var set during useEffect
- Is it possible to set a form input to 0px height?
- Avoid loading data passed as props with React Router
- React Matrial Multiselect defaultValue are not selected
- Not able to receive/set cookies in browser from backend in MERN app with backend hosted on heroku and frontend on netlify
- How do I deal with promises in setState?
- Uncaught Error: Objects are not valid as a React child. when using react-flow-editor
- Javascript: How to use adjacent sibling selector in jss with <input type=radio> // change color when clicked
- How to set a date string to a the following format
- How to use .destory() on <TinySlider></TinySlider>
- Activating the manipulation system in react-graph-vis
- Warning: Each child in a list should have a unique "key" prop but i have key props
- If I was mapping thru a collection, and placing buttons for each doc, how could I grab the docID from the button to its function?
- Why does React.createRef() for material-ui Button element in TypeScript not work correctly?
- Find object in array?
- How to set a value on a specific page template in Gatsby
- require('devtron').install() causes "Uncaught TypeError: Cannot read property 'BrowserWindow' of undefined" in electron app
- Absolute path not working in create-react-app
- Why is my renderer failing when using Material-UI using Jest and react-test-renderer?
- React: Passing props to parent returns <empy string>
- Django DRF + Allauth: OAuth2Error: Error retrieving access token on production build
- React: this.function is not a function
- How to use bootstrap popover with reactjs