DEV Community

Cover image for 7 Free APIs for Your Next Projects
Vishal Yadav
Vishal Yadav

Posted on

7 Free APIs for Your Next Projects

gIF

1. Mapbox API Example

Mapbox offers comprehensive tools and accurate location data that you can use to create maps, navigation services, and other location-based applications. With Mapbox, you can display custom maps, integrate geolocation, and much more.
Link

import React, { useEffect } from 'react';

const Mapbox = () => {
    useEffect(() => {
        // Set your Mapbox access token here
        const mapboxAccessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';

        // Create a map instance
        const map = new mapboxgl.Map({
            container: 'map', // Container ID in the HTML
            style: 'mapbox://styles/mapbox/streets-v11', // Style URL
            center: [-74.5, 40], // Starting position [lng, lat]
            zoom: 9, // Starting zoom
        });

        mapboxgl.accessToken = mapboxAccessToken;
    }, []);

    return (
        <div>
            <h2>Mapbox Example</h2>
            <div id="map" style={{ width: '100%', height: '400px' }}></div>
        </div>
    );
};

export default Mapbox;
Enter fullscreen mode Exit fullscreen mode

2. NASA API Example

The NASA API provides access to a wealth of data related to space, including images, videos, and information about planets, stars, and more. Whether you’re building an educational tool or just want to display fascinating space data, NASA’s API is an excellent resource.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const Nasa = () => {
    const [data, setData] = useState(null);

    useEffect(() => {
        axios.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY')
            .then(response => setData(response.data))
            .catch(error => console.error('Error fetching data from NASA API:', error));
    }, []);

    return (
        <div>
            <h2>NASA Astronomy Picture of the Day</h2>
            {data ? (
                <div>
                    <h3>{data.title}</h3>
                    <img src={data.url} alt={data.title} style={{ maxWidth: '100%' }} />
                    <p>{data.explanation}</p>
                </div>
            ) : (
                <p>Loading...</p>
            )}
        </div>
    );
};

export default Nasa;
Enter fullscreen mode Exit fullscreen mode

3. Favorite Quotes API Example

This API offers a collection of insightful quotes that you can easily integrate into your application. It’s perfect for creating apps that inspire and motivate users.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const Quotes = () => {
    const [quote, setQuote] = useState('');

    useEffect(() => {
        axios.get('https://favqs.com/api/qotd')
            .then(response => setQuote(response.data.quote.body))
            .catch(error => console.error('Error fetching data from Quotes API:', error));
    }, []);

    return (
        <div>
            <h2>Quote of the Day</h2>
            <blockquote>{quote}</blockquote>
        </div>
    );
};

export default Quotes;
Enter fullscreen mode Exit fullscreen mode

4. Edamam API Example

Edamam provides access to a comprehensive database of food items and recipes, along with detailed health analyses. This API is ideal for creating diet trackers, recipe apps, and nutrition-based applications.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const Edamam = () => {
    const [recipes, setRecipes] = useState([]);
    const query = "chicken"; // Example search query

    useEffect(() => {
        const appId = 'YOUR_EDAMAM_APP_ID';
        const appKey = 'YOUR_EDAMAM_APP_KEY';

        axios.get(`https://api.edamam.com/search?q=${query}&app_id=${appId}&app_key=${appKey}`)
            .then(response => setRecipes(response.data.hits))
            .catch(error => console.error('Error fetching data from Edamam API:', error));
    }, []);

    return (
        <div>
            <h2>Edamam Recipes for "{query}"</h2>
            <ul>
                {recipes.map((recipe, index) => (
                    <li key={index}>
                        <img src={recipe.recipe.image} alt={recipe.recipe.label} width="50" />
                        {recipe.recipe.label}
                    </li>
                ))}
            </ul>
        </div>
    );
};

export default Edamam;
Enter fullscreen mode Exit fullscreen mode

5. Fake Store API Example

The Fake Store API is a fantastic tool for developers working on e-commerce projects. It provides pseudo-real data that you can use to populate your store with products, prices, and categories.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const FakeStore = () => {
    const [products, setProducts] = useState([]);

    useEffect(() => {
        axios.get('https://fakestoreapi.com/products')
            .then(response => setProducts(response.data))
            .catch(error => console.error('Error fetching data from Fake Store API:', error));
    }, []);

    return (
        <div>
            <h2>Fake Store Products</h2>
            <ul>
                {products.map(product => (
                    <li key={product.id}>
                        <img src={product.image} alt={product.title} width="50" />
                        {product.title}
                    </li>
                ))}
            </ul>
        </div>
    );
};

export default FakeStore;
Enter fullscreen mode Exit fullscreen mode

6. Pokémon API Example

The Pokémon API (PokeAPI) is a must-have for any Pokémon fan. It offers comprehensive data on all Pokémon, including stats, types, and abilities, making it perfect for building Pokémon-related apps and games.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const Pokemon = () => {
    const [pokemonList, setPokemonList] = useState([]);

    useEffect(() => {
        axios.get('https://pokeapi.co/api/v2/pokemon?limit=10')
            .then(response => setPokemonList(response.data.results))
            .catch(error => console.error('Error fetching data from Pokémon API:', error));
    }, []);

    return (
        <div>
            <h2>Pokémon List</h2>
            <ul>
                {pokemonList.map((pokemon, index) => (
                    <li key={index}>
                        {pokemon.name}
                    </li>
                ))}
            </ul>
        </div>
    );
};

export default Pokemon;
Enter fullscreen mode Exit fullscreen mode

7. IGDB API Example

The Internet Games Database (IGDB) API provides data on thousands of video games, allowing you to create video game-oriented websites and applications. You can fetch information about games, platforms, genres, and more.
Link

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const IGDB = () => {
    const [games, setGames] = useState([]);

    useEffect(() => {
        const apiKey = 'YOUR_IGDB_API_KEY';

        axios.post('https://api.igdb.com/v4/games/', 
        'fields name, cover.url; sort popularity desc; limit 10;', 
        { headers: { 'Client-ID': 'YOUR_CLIENT_ID', 'Authorization': `Bearer ${apiKey}` } })
            .then(response => setGames(response.data))
            .catch(error => console.error('Error fetching data from IGDB API:', error));
    }, []);

    return (
        <div>
            <h2>Popular Video Games</h2>
            <ul>
                {games.map(game => (
                    <li key={game.id}>
                        {game.cover ? <img src={game.cover.url} alt={game.name} width="50" /> : null}
                        {game.name}
                    </li>
                ))}
            </ul>
        </div>
    );
};

export default IGDB;
Enter fullscreen mode Exit fullscreen mode

Conclusion

Each of these examples shows how to integrate the respective APIs into a React, Next. You can easily extend these examples to fit your application’s needs, whether it’s displaying more detailed information, handling user interactions, or styling the output for better UX.

These examples demonstrate how straightforward it is to fetch and display data from various free APIs.

Top comments (37)

Collapse
 
akash_deshmukh_0a5782423f profile image
AKASH DESHMUKH

Thanks. finds informational !

Collapse
 
vyan profile image
Vishal Yadav

Cool

Collapse
 
vijay_inkrefuge_2ac6bbadc profile image
vijay inkrefuge • Edited

But map box require credit card

Collapse
 
jason_29317 profile image
Jason Claeys

I use OpenStreetMap + Leaflet.js when I need free mapping. I've also used OpenCage for geocoding, which you can try for free, without having to enter in card data.

Collapse
 
vyan profile image
Vishal Yadav

Nice

Collapse
 
eakkasit profile image
EA

Love leaflet js too.

Collapse
 
justine_awunudo profile image
Justine Awunudo

You can use maptiler also

Collapse
 
mahendraputra21 profile image
Dewa Mahendra

you can use dummyJson also
dummyjson.com/

Collapse
 
vyan profile image
Vishal Yadav

Yeah

Collapse
 
zakaria_jeddi_631600d9b7 profile image
Zakar’IA Jeddi

Dingue !

Premiére connection sur ce site et wowwww je tombe directement sur un articles qui solutionne un probleme que je pensais avoir !!!!!

Je debute dans la programmation, seul je galére un peu mais j'aime ça c'est stimulant !!!
Hate d'echanger averc vous tous !

Collapse
 
sachinkraj profile image
Sachin Kumar Rajput

Thanks for the list, is there a free API for detecting users location. I know a package provided by maxmind.

Collapse
 
vyan profile image
Vishal Yadav

Actually , i also know that only.

Collapse
 
tomasdevs profile image
Tomas Stveracek

Great list of APIs! I'm always looking for new tools for my projects, and some of these are new to me. Thanks for sharing!

Collapse
 
hosseinyazdi profile image
Hossein Yazdi

Thanks for the share! I would also like to mention API Tracker, which has the world's largest API database.

Collapse
 
samuel2935 profile image
Samuel

Very helpful.

Collapse
 
sarmaakondi profile image
Sarma Akondi V N M

Thanks a lot 😁

Collapse
 
syedmuhammadaliraza profile image
Syed Muhammad Ali Raza

👍

Collapse
 
shravan1908 profile image
Shravan

I host a emojipasta generator API lol. Check it out: github.com/shravanasati/emozi-website

Collapse
 
vyan profile image
Vishal Yadav

Nice one

Collapse
 
mohamed_karim_2dddebb42bd profile image
mohamed karim

Thank for sharing

Collapse
 
matin676 profile image
Matin Imam

Nice collection, Thanks 🤘☺️

Collapse
 
kin7777 profile image
kince marando

kindly sir
thank you so much for sharing this great information .

Collapse
 
eren_yeager_c1759662d1eae profile image
eren yeager

nice

Collapse
 
vyan profile image
Vishal Yadav

Tq

Some comments may only be visible to logged-in visitors. Sign in to view all comments.