Help needed - API

Help needed - API
0

#1

Guys i am stuck on the projects using API,i am done with basic algo and honestly i had no problem, but since the projects use API, i need sources to understand it.
if you had the same problem, please share how you coped up with it.
Thanks


#2

Hmm, I don’t remember how I learned to use APIs but here is how it works.

  1. You do a request to the API, you can use the fetch API, axios or even jQuery (among other libraries).
  2. You get either a successful response or an error, you should handle both cases, for instance if you use axios it would look like this:
axios.get(url)
  .then(res => {
    console.log("This was a successful response, here is the data")
    console.log(res.data) 
  })
  .catch(err => {
    console.error(err)
  })

You have to keep in mind, almost all of the API responses will be an object that contains a data property, inside the data you find what you’ve asked for.

You can save the data in a variable and start working with it in your application.