"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > ree APIs for Your Next Projects

ree APIs for Your Next Projects

Published on 2024-08-24
Browse:894

ree APIs for Your Next Projects

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 (
        

Mapbox Example

); }; export default Mapbox;

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 (
        

NASA Astronomy Picture of the Day

{data ? (

{data.title}

{data.title}

{data.explanation}

) : (

Loading...

)}
); }; export default Nasa;

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 (
        

Quote of the Day

{quote}
); }; export default Quotes;

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 (
        

Edamam Recipes for "{query}"

    {recipes.map((recipe, index) => (
  • {recipe.recipe.label} {recipe.recipe.label}
  • ))}
); }; export default Edamam;

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 (
        

Fake Store Products

    {products.map(product => (
  • {product.title} {product.title}
  • ))}
); }; export default FakeStore;

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 (
        

Pokémon List

    {pokemonList.map((pokemon, index) => (
  • {pokemon.name}
  • ))}
); }; export default Pokemon;

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 (
        

Popular Video Games

    {games.map(game => (
  • {game.cover ? {game.name} : null} {game.name}
  • ))}
); }; export default IGDB;

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.

Release Statement This article is reproduced at: https://dev.to/vyan/7-free-apis-for-your-next-projects-50n3?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3