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的五大趋势,你是否已经了解?
308 0
|
8月前
|
人工智能 Linux 文件存储
旧台式电脑的 10 种用途
旧台式电脑的 10 种用途
387 14
|
10月前
|
安全 API 数据处理
鸿蒙next版开发:ArkTS组件通用属性(隐私遮罩)
在HarmonyOS 5.0中,ArkTS引入了隐私遮罩功能,用于保护用户隐私和数据安全。本文详细介绍了隐私遮罩的通用属性和使用方法,并提供了示例代码。隐私遮罩支持Image和Text组件,在数据加载或处理过程中防止敏感信息泄露,提升用户体验和数据安全性。
321 11
|
11月前
|
安全 前端开发 iOS开发
揭秘 electron-builder:macOS 应用打包背后到底发生了什么?
本文详细介绍了 Electron 应用在 macOS 平台上的打包流程,涵盖配置文件、打包步骤、签名及 notarization 等关键环节。通过剖析 `electron-builder` 的源码,展示了如何处理多架构应用、执行签名,并解决常见问题。适合希望深入了解 macOS 打包细节的开发者。
470 2
|
11月前
|
Rust 前端开发 iOS开发
打造《黑神话:悟空》壁纸软件:使用 Tauri 快速上手
本文首发于微信公众号“前端徐徐”。作者分享了如何仅用半天时间实现《黑神话:悟空》桌面壁纸软件的过程,并展示了实际效果。文中详细介绍了使用 Tauri 开发跨平台桌面应用的核心流程与关键技术,包括下载壁纸、更换壁纸以及前后端交互等细节。此外,还提供了源码和下载链接供读者体验。
159 0
打造《黑神话:悟空》壁纸软件:使用 Tauri 快速上手
|
编解码 小程序
无影云电脑产品使用黑神话悟空之:游戏服务器更新/配置问题
该文档主要介绍了使用无影云电脑玩《黑神话:悟空》时可能遇到的问题及解决方法,包括游戏服务器更新、配置问题、画质建议及如何开启帧数显示等内容,并提供了详细的步骤指导与参考链接。
|
JavaScript
Vue2全局提示(Message)
这篇文章介绍了如何在Vue 3框架中创建一个全局提示组件(Message),支持自定义提示的持续时间和位置,并且可以展示多种类型(info, success, error, warn)的消息提示。
317 0
Vue2全局提示(Message)
|
人工智能 监控 安全
巧用通义灵码助力护网面试
护网行动是公安部组织的网络安全评估活动,通过模拟攻防演练提升企事业单位安全防护能力。自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)
515 7
|
JSON API 网络架构
12 个值得收藏的免费 API
当你准备开始创建一个新的应用,学习一门新的技术,开发一个新的功能的时候;当你已经做好了所有的准备,这个时候你在想:我的数据要如何去模拟生成?
640 0
12 个值得收藏的免费 API