Web API's

I need help with API’s. Its extremely confusing as there are many of them. Before anyone suggests github users i have already used it …are there any more? Why are some free and other are not? i have tons of questions on APi that i cant get any answers for … :frowning:

have you looked here?

https://any-api.com/

I also can’t stress enough to read the documentation. (but it sounds like you already do that). :slight_smile:

1 Like

I wrote a very extensive answer about API’s here:

API for Web-development

Why certain API are frees while others are not, is more a business question. I would argue that sites like Spotify and Youtube have free API’s so that if other developers use the API, spotify and youtube can serve ads by which they make money

while other API’s use a different revenue model, instead charging for the usage of the API. When building an application, sometimes using an API is cheaper then building everything from scratch yourself.

and API needs to be build, maintained and expanded. Which cost money, so you need a revenue stream.

2 Likes

thanks for your reply …

Having a really hard time today :frowning:

_ below is a snippet of an Ajax XMLHttpRequest to github users endpoint. The higher order function map() iterates over the original array and returns a new array based of a condition. The data variable is my object/array/object of github users in json format that the server sent back. So i have declared a new variable userData - taken data and used map on it ,which by rights -should make userData an array - when i have console.log(typeof userData)- it still says its an object :persevere: :face_with_raised_eyebrow:

const xhr = new XMLHttpRequest();
const url = 'https://api.github.com/users';
  
xhr.open('GET', url, true);
  xhr.onload = function(){ 
    if(xhr.status >= 200 && xhr.status < 400){
      let data = JSON.parse(this.response);
        console.log(data)
      let userData = data.map(index => index);
        console.log(userData)
      } else{
      console.log('we connected to the server, but it returned an error.');
      }
    };
    
  xhr.send();

Welcome to the wonderful I would like to call JS quirks, The first answer in this stackoverflow question covers reliable ways to test for array:

https://stackoverflow.com/questions/12996871/why-does-typeof-array-with-objects-return-object-and-not-array

the second covers some background info (difficult read)

2 Likes

thanks @stetim94 the API stuff literally drained my energy. I woke up early and was looking forward to attacking this API stuff today and have just been met with frustration and confusion but thank you @lisalisaj + @stetim94 , i will check those links out tomorrow :wink:

1 Like

@lisalisaj than you lisa i havent and i will tomorrow :innocent:

1 Like

@stetim94 Hey stetim , i read your article. Thing is i know what it is - i get that - its the using it im having trouble with. Implementing in my projects. I tried a bing news search rapidapi yesterday. I got a bunch of data but but not through ‘form’ user input (which is what i want to happen) but through a Http GET request - which were the top coronavirus stories from around the world - but i made the query on the rapidapi site when i was testing the api? and it sent me those same results? I also think this type of request would come under a ‘POST’ not ‘GET’ because the client is sending data TO the server and the server is taking that data - analyzing it - and sending a response. I was trying to build say build - a simple form with submit button - user types in - say - london news - and hits submit , sends request to server - server responds with (data) all news relevant to London uk.

Seems you need to improve your overall understanding. Have you ever worked with a database and done queries? Maybe learning something about back-end will improve your overall understanding of API’s.

that is not the difference between POST and GET. If we send sensitive data, we should indeed use POST. but we can perfectly send data with a GET request as well. In fact, for a search page I prefer GET, given then the search result page can be bookmarked

Looking at the documentation:

the search query (q) is a mandatory parameter, so you could just extract the user input from the form and use it for the API request?

1 Like

That is the exact same APi i was trying to use!! and thats what i was tring to do lol but how do you send the user input - via query string right? I have all the peices of the puzzle - im just need to clarify a few things i think …and to answer your question - i have xampp installed which includes phpmyadmin and i have saved a users data - added users to database - manipulate/update/delete data using PUT and DELETE but i think your talking more along the Data Science route …?

This help you understand how Bing has a database which you query through the API? Being able to “see” this, helps massively

Its in the documentation/my screenshot which query parameter you have to use to send the user input. I don’t see the problem?

there isn’t one , just needed clarification - thank you!
Its my first time making this sort of request.

spend the past 40 minutes trying to figure out why i cant use this - i have subscribed. There is no pop ups on what i need to do to get test this API … nothing! So im here going round and round in circles. Only one i can see that i can use is GET trending and i dont want that as it doesn’t require a prarmeter

1 Like