One of the best thing out there for developer's to get handful of data for the next project. Lets see what Public API's are in here.
Public API ?
The former is just self explanatory as this thing is just available to all and free to use and later (API-Application Program Interface) is what connects multiple software's. There are also private API's with propagates between Frontend and backend of a firm.
The best way to know of these wide varieties of API's is to explore the GitHub. Choose one of your favorite one.
How actually to use these!!
Here I'm gonna use MealDB to demonstrate the working.
- Read the documentation (else we are just carrying a trolley which got wheels).
- Fetch the data that you want to use.
- Convert it to JSON format.
- Access the data using native JavaScript Object access methods (dot or bracket notation).
Accessing a random meal from MealDB.
async function getRandomMeal() { //ES6 async keyword for asynchronous flow of data
const response = await fetch('https://www.themealdb.com/api/json/v1/1/random.php');
//fetch URL which gives a random meal
const responseJSON = await response.json(); //convert to JSON format
const randomMeal = responseJSON.meals[0]; //access the meal data
console.log(randomMeal); //logs the output(random meal data)
}
Cool website using MealDB
As a part of Florin Pop's projects I created Chef'sHub website.
- Fetches random meal
- Add Favorite meals
- Search for specific meal
since I'm new to API's I just followed the tutorial
Hope you all got something to take in from here. Share your thoughts and queries