Skip to content

Instantly share code, notes, and snippets.

@DominicGBauer
Last active February 17, 2019 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicGBauer/e0b08ef5c39c68f199eae069d41b9122 to your computer and use it in GitHub Desktop.
Save DominicGBauer/e0b08ef5c39c68f199eae069d41b9122 to your computer and use it in GitHub Desktop.
import axios from 'axios'
// Create a KEY variable for the NASA API key you received earlier
// Make sure it's in quotations
const KEY = 'YOUR KEY'
// Create a nasa variable that we will use to perform our API request
// Axios is going to create a url for us that conforms to NASA's
// specifications
let nasa = axios.create({
// baseURL is the url we saw ealier to access the APOD data
baseURL: 'https://api.nasa.gov/planetary/apod',
// params are the query parameters we can set
// I am chosing the date of 10 February 2019 (when I wrote this blog)
// I chose HD to be true (cause why not :)?)
// Finally the api_key is simply the key we got from NASA
params: {
date: '2019-02-10', // Don't forget the quotations
hd: true,
api_key: KEY
}
// Essentially this will create a url that looks like this
// https://api.nasa.gov/planetary/apod?date=2019-02-10&hd=true&api_key=KEY
})
class App extends React.Component {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment