2024你不得不知道的免费API

简介: 本文首发于微信公众号“前端徐徐”,介绍了 2024 年各领域的免费 API 列表,涵盖游戏、语言、音乐、安全、科学、体育、Web 应用、产品、健康、政府和地理、食品、开源项目、电影和漫画等多个类别。每个 API 均提供官网链接、简介及示例代码,帮助开发者轻松集成第三方服务,增强应用程序的功能和用户体验。

本文首发微信公众号:前端徐徐。

前言

API(应用程序编程接口)是开发人员必不可少的工具,使他们能够将第三方服务集成到他们的应用程序中。以下是 2024 年各个类别的免费 API 的详尽列表,以及每个 API 的网站链接、说明和示例代码。

游戏类

Steam Community API

  • 官网: steamcommunity.com/dev
  • 简介: Steamworks Web API 提供了各种 Steam 功能(例如用户身份验证、库存管理和游戏数据)的接口。
  • 示例:
const fetch = require('node-fetch');
const steamApiKey = 'YOUR_STEAM_API_KEY';
const steamId = 'STEAM_USER_ID';
const url = `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${steamApiKey}&steamids=${steamId}`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Riot Games API

  • 官网: developer.riotgames.com
  • 简介: 访问《英雄联盟》、《云顶之弈》、《Valorant》等游戏的数据。提供有关比赛、排名、冠军和其他游戏相关统计数据。
  • 示例:
const fetch = require('node-fetch');
const riotApiKey = 'YOUR_RIOT_API_KEY';
const summonerName = 'SUMMONER_NAME';
const url = `https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/${summonerName}?api_key=${riotApiKey}`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

语言类

Evil Insult Generator API

  • : evilinsult.com/api
  • 简介: 为了好玩或测试目的,用各种语言随机生成侮辱性话语。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://evilinsult.com/generate_insult.php?lang=en&type=json';
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Fun Translations API

  • 官网: funtranslations.com/api
  • 简介: 将文本翻译成各种有趣的语言,如尤达语言、莎士比亚语言、小黄人语言等等。
  • 示例:
const fetch = require('node-fetch');
const text = 'Hello, world!';
const url = `https://api.funtranslations.com/translate/yoda.json?text=${encodeURIComponent(text)}`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

音乐类

Spotify Web API

const fetch = require('node-fetch');
const accessToken = 'YOUR_SPOTIFY_ACCESS_TOKEN';
const url = 'https://api.spotify.com/v1/me/player/recently-played';
fetch(url, {
  headers: {
    'Authorization': `Bearer ${accessToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

安全类

Have I Been Pwned API

  • 官网: haveibeenpwned.com/API/v2
  • 简介: 检查您的电子邮件或用户名是否已遭遇数据泄露。提供有关泄露、粘贴和密码泄露的数据。
  • 示例:
const fetch = require('node-fetch');
const email = 'test@example.com';
const url = `https://haveibeenpwned.com/api/v2/breachedaccount/${email}`;
fetch(url, {
  headers: {
    'User-Agent': 'Node.js'
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

hodan API

  • 官网: developer.shodan.io
  • 简介: Shodan 是一个互联网连接设备的搜索引擎。它提供全球各种服务器、设备和系统的数据。
  • 示例:
const fetch = require('node-fetch');
const shodanApiKey = 'YOUR_SHODAN_API_KEY';
const query = 'apache';
const url = `https://api.shodan.io/shodan/host/search?key=${shodanApiKey}&query=${query}`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

科学类

NASA API

  • 官网: api.nasa.gov
  • 简介: 访问 NASA 数据集中的数据,包括天文照片、行星数据等。
  • 示例:
const fetch = require('node-fetch');
const nasaApiKey = 'YOUR_NASA_API_KEY';
const url = `https://api.nasa.gov/planetary/apod?api_key=${nasaApiKey}`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Wolfram Alpha API

  • 官网: products.wolframalpha.com/api
  • 简介: 提供对 Wolfram Alpha 的大量计算知识的访问,包括数学计算、数据分析等。
  • 示例:
const fetch = require('node-fetch');
const wolframAppId = 'YOUR_WOLFRAM_APP_ID';
const query = 'integrate x^2';
const url = `http://api.wolframalpha.com/v2/query?input=${encodeURIComponent(query)}&appid=${wolframAppId}&output=json`;
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Open Science Framework API

  • 官网: developer.osf.io
  • 简介: 从开放科学框架访问研究数据、项目管理工具和其他科学资源。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://api.osf.io/v2/nodes/';
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

体育类

NBA API

const fetch = require('node-fetch');
const url = 'https://api-nba-v1.p.rapidapi.com/teams/league/standard';
const options = {
  method: 'GET',
  headers: {
    'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY',
    'X-RapidAPI-Host': 'api-nba-v1.p.rapidapi.com'
  }
};
fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Web应用类

Discord API

const fetch = require('node-fetch');
const discordToken = 'YOUR_DISCORD_BOT_TOKEN';
const url = 'https://discord.com/api/users/@me';
fetch(url, {
  headers: {
    'Authorization': `Bot ${discordToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Slack API

  • 官网: api.slack.com
  • 简介: 访问 Slack 功能,例如消息传递、用户数据和工作区管理。
  • 示例:
const fetch = require('node-fetch');
const slackToken = 'YOUR_SLACK_API_TOKEN';
const url = 'https://slack.com/api/conversations.list';
fetch(url, {
  headers: {
    'Authorization': `Bearer ${slackToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

产品类

Car Query API

  • 官网: carqueryapi.com
  • 简介: 访问汽车数据,包括品牌、型号和年份信息。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://www.carqueryapi.com/api/0.3/?cmd=getMakes';
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Yelp API

  • 官网: yelp.com/developers
  • 简介: 访问本地企业的数据,包括评论、评级和企业详情。
  • 示例:
const fetch = require('node-fetch');
const yelpApiKey = 'YOUR_YELP_API_KEY';
const url = 'https://api.yelp.com/v3/businesses/search?location=San Francisco';
fetch(url, {
  headers: {
    'Authorization': `Bearer ${yelpApiKey}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

健康类

Healthcare.gov API

  • 官网: healthcare.gov/developers
  • 简介: 访问有关医疗保健计划、提供商目录和其他健康相关信息的数据。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://data.healthcare.gov/resource/xyz123.json';
fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

政府和地理类

Code.gov API

  • 官网: code.gov
  • 简介: 访问联邦政府软件项目的数据,包括代码存储库和项目详细信息。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://api.code.gov/projects';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Data.gov API

  • 官网: data.gov/developers/apis
  • 简介: 访问美国政府的广泛数据集,包括天气、教育和健康数据。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://api.data.gov/ed/collegescorecard/v1/schools.json?api_key=YOUR_DATA_GOV_API_KEY';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Data.europa.eu API

  • 官网: data.europa.eu/en
  • 简介: 访问来自欧盟机构和团体的开放数据。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://data.europa.eu/api/hub/search/datasets';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

TransLoc API

const fetch = require('node-fetch');
const translocApiKey = 'YOUR_TRANSLOC_API_KEY';
const url = 'https://transloc-api-1-2.p.rapidapi.com/agencies.json';
fetch(url, {
    headers: {
        'X-RapidAPI-Key': translocApiKey,
        'X-RapidAPI-Host': 'transloc-api-1-2.p.rapidapi.com'
    }
})
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

食品类

Open Food Facts API

const fetch = require('node-fetch');
const url = 'https://world.openfoodfacts.org/api/v0/product/737628064502.json';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Taco Fancy API

const fetch = require('node-fetch');
const url = 'http://taco-randomizer.herokuapp.com/random/';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

开源项目类

Libraries.io API

  • 官网: libraries.io/api
  • 简介: 访问有关开源项目的数据,包括依赖信息、版本历史记录等。
  • 示例:
const fetch = require('node-fetch');
const librariesApiKey = 'YOUR_LIBRARIES_IO_API_KEY';
const url = `https://libraries.io/api/platforms?api_key=${librariesApiKey}`;
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

电影和漫画类

Chuck Norris Jokes API

const fetch = require('node-fetch');
const url = 'https://api.chucknorris.io/jokes/random';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Final Space API

  • 官网: finalspaceapi.com
  • 简介: 访问《太空终界》电视节目的数据,包括角色、剧集等。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://finalspaceapi.com/api/v0/character';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Kitsu API

  • 官网: kitsu.docs.apiary.io
  • 简介:访问动漫和漫画的数据,包括系列信息、评论和用户评分。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://kitsu.io/api/edge/anime';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Marvel API

  • 官网: developer.marvel.com
  • 简介: 访问有关漫威漫画、人物和创作者的数据。
  • 示例:
const fetch = require('node-fetch');
const marvelPublicKey = 'YOUR_MARVEL_PUBLIC_KEY';
const marvelPrivateKey = 'YOUR_MARVEL_PRIVATE_KEY';
const ts = new Date().getTime();
const hash = require('crypto').createHash('md5').update(ts + marvelPrivateKey + marvelPublicKey).digest('hex');
const url = `https://gateway.marvel.com/v1/public/characters?ts=${ts}&apikey=${marvelPublicKey}&hash=${hash}`;
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

PokeAPI

  • 官网: pokeapi.co
  • 简介:访问有关 Pokémon 的数据,包括种类、能力和游戏信息。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://pokeapi.co/api/v2/pokemon/ditto';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Rick and Morty API

  • 官网: rickandmortyapi.com
  • 简介: 访问 Rick and Morty 电视节目的数据,包括角色、剧集和地点。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://rickandmortyapi.com/api/character';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Simpsons Quotes API

const fetch = require('node-fetch');
const url = 'https://thesimpsonsquoteapi.glitch.me/quotes';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Star Wars API

  • 官网: swapi.tech
  • 简介: 访问有关星球大战宇宙的数据,包括电影、人物、星际飞船和行星。
  • 示例:
const fetch = require('node-fetch');
const url = 'https://swapi.tech/api/people/1';
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Superhero API

  • 官网: superheroapi.com
  • 简介: 访问有关各种超级英雄的数据,包括他们的力量、传记和图像。
  • 示例:
const fetch = require('node-fetch');
const superheroApiKey = 'YOUR_SUPERHERO_API_KEY';
const url = `https://superheroapi.com/api/${superheroApiKey}/1`;
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

总结

2024 年免费 API 的完整列表涵盖了广泛的类别,为开发人员提供了大量机会,以强大而多样的功能增强他们的应用程序。从游戏和音乐到科学和政府数据,这些 API 为创建创新且引人入胜的项目提供了宝贵的资源。

请随意探索这些 API 并将其集成到您的项目中,以解锁新的可能性和功能。祝您编码愉快!

相关文章
|
算法 测试技术 区块链
Web3.0的五大趋势,你是否已经了解?
Web3.0的五大趋势,你是否已经了解?
401 0
|
7月前
|
JSON 供应链 API
商品条码查询 API 实战指南:掌握商品“唯一身份标识”
商品条码查询API简介:基于1974年诞生的条码技术,该API通过输入13/14位条码,快速获取商品基本信息(名称、品牌、规格等)和成分信息(营养成分、配料表等)。其核心功能包括商品条码查询接口与成分查询接口,广泛应用于零售、电商、物流及健康饮食等领域。支持HTTP POST请求,提供便捷的代码调用示例。作为数字化转型的重要工具,它不仅方便消费者查询商品详情,还助力商家优化库存管理与销售流程,提升运营效率。
1847 3
|
人工智能 Linux 文件存储
旧台式电脑的 10 种用途
旧台式电脑的 10 种用途
815 14
|
12月前
|
算法 Java 编译器
深入理解 Java JDK —— 让我们从基础到进阶
JDK(Java Development Kit)是 Java 开发的核心工具包,包含编译、运行和调试 Java 程序所需的所有工具和库。它主要由 JVM(Java 虚拟机)、JRE(Java 运行时环境)和 Java 核心类库组成。JVM 是跨平台运行的基础,负责字节码的加载、执行和内存管理;JRE 提供运行 Java 应用的环境;核心类库则提供了丰富的 API 支持。通过编写、编译和运行一个简单的 Java 程序,可以深入理解 JDK 的工作原理。此外,JDK 还提供了 JIT 编译、垃圾回收优化和并发工具包等高级功能,帮助开发者提高程序性能和稳定性。
1437 10
|
存储 Linux 开发工具
告别Hugging Face模型下载难题:掌握高效下载策略,畅享无缝开发体验
【8月更文挑战第2天】告别Hugging Face模型下载难题:掌握高效下载策略,畅享无缝开发体验
4205 64
告别Hugging Face模型下载难题:掌握高效下载策略,畅享无缝开发体验
|
Java 开发者 Spring
Spring bean的生命周期详解!
本文详细解析Spring Bean的生命周期及其核心概念,并深入源码分析。Spring Bean是Spring框架的核心,由容器管理其生命周期。从实例化到销毁,共经历十个阶段,包括属性赋值、接口回调、初始化及销毁等。通过剖析`BeanFactory`、`ApplicationContext`等关键接口与类,帮助你深入了解Spring Bean的管理机制。希望本文能助你更好地掌握Spring Bean生命周期。
1206 1
|
人工智能 监控 决策智能
震惊!多角色 Agent 携手合作,竟能如此高效搞定复杂任务,背后秘密大揭晓!
在复杂任务环境中,单个智能体常因能力与资源限制而难以应对。多智能体系统(multi-agent systems)通过将任务分解并分配给各具专长的智能体,实现了高效协同工作。例如,在物流配送中,不同智能体分别处理路线规划、货物装载与交通监控,确保任务准确高效完成。同样,在大型游戏开发项目里,各智能体专注剧情设计、美术创作等特定领域,显著提升项目质量和开发速度。通过共享信息、协商决策等方式,多智能体系统展现出强大灵活性与适应性,为物流、软件开发等领域带来新机遇。
638 2
|
JSON API 网络架构
12 个值得收藏的免费 API
当你准备开始创建一个新的应用,学习一门新的技术,开发一个新的功能的时候;当你已经做好了所有的准备,这个时候你在想:我的数据要如何去模拟生成?
738 0
12 个值得收藏的免费 API
|
人工智能 监控 安全
巧用通义灵码助力护网面试
护网行动是公安部组织的网络安全评估活动,通过模拟攻防演练提升企事业单位安全防护能力。自2016年起,涉及单位逐年增加,网络安全已成为业务保障必需。行动分为红蓝两队,红队模拟攻击,蓝队负责防御。在面试中,蓝队工程师岗位分为初级、中级和高级,要求包括漏洞分析、应急响应和安全设备操作。通义灵码作为AI工具,可用于面试准备,如分析日志、撰写脚本和辅助报告撰写,提高应聘者表现。红队面试侧重实战经验,如渗透测试和漏洞利用,通义灵码也可在代码审查和策略规划上提供帮助。请遵守中国国家网络安全法!!!网络不是法外之地!!!
|
机器学习/深度学习 计算机视觉
字节豆包全新图像Tokenizer:生成图像最低只需32个token,最高提速410倍
【7月更文挑战第1天】新方法将图像转为1D token序列,减少计算复杂度,提高生成效率。在保持高画质(如gFID: 1.97 on ImageNet 256x256)的同时,TiTok比现有模型快410倍。虽有资源需求及token限制问题,但展示了图像处理的新方向。[论文链接](https://arxiv.org/abs/2406.07550)
741 7