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 并将其集成到您的项目中,以解锁新的可能性和功能。祝您编码愉快!

相关文章
|
JSON API 数据格式
豆瓣电影api系列
豆瓣电影api系列
豆瓣电影api系列
|
4月前
|
Kubernetes Cloud Native Nacos
MCP 网关实战:基于 Higress + Nacos 的零代码工具扩展方案
本文介绍一种基于开源 Higress 与 Nacos 的私有化 MCP 智能体网关架构,实现工具动态注册、Prompt 实时更新、多租户安全隔离,并支持在无外网、无 Helm 的生产环境中一键部署。
719 25
MCP 网关实战:基于 Higress + Nacos 的零代码工具扩展方案
|
3月前
|
JSON API 网络架构
什么是API?API有哪些类型?
本文深入浅出地讲解API的概念、类型及应用。API即应用程序接口,是软件间通信的桥梁。文章从开放、内部、合作伙伴API等分类入手,解析REST、SOAP、GraphQL等技术类型,并探讨其在数据与功能调用中的作用,帮助读者全面理解现代数字服务的底层逻辑。
8868 10
|
3月前
|
人工智能 程序员 API
大模型不是终点,黎跃春揭秘AI智能体运营工程师的翻盘机会
程序员失业潮下,黎跃春带你拆解AI智能体运营工程师的转型路径。深度解析如何利用Coze平台构建“数字员工”,实现职业转型迁徙。
|
4月前
|
网络协议 API 定位技术
全球IP归属地查询免费API详细指南
接口盒子提供免费全球IP归属地查询API,支持IPv4/IPv6,返回国家、省、市、运营商及经纬度等详细信息。多通道查询保障准确性,无每日调用上限,适用于网站分析、安全防护、内容本地化等场景。
1348 0
|
9月前
|
JSON API PHP
通用图片搜索API:百度源免费接口教程
本文介绍一款基于百度图片搜索的免费API接口,由接口盒子提供。支持关键词搜索,具备详细请求与返回参数说明,并提供PHP及Python调用示例。开发者可快速集成实现图片搜索功能,适用于内容聚合、素材库建设等场景。
1450 0
|
自然语言处理 搜索推荐 小程序
微信公众号接口:解锁公众号开发的无限可能
微信公众号接口是微信官方提供的API,支持开发者通过编程与公众号交互,实现自动回复、消息管理、用户管理和数据分析等功能。本文深入探讨接口的定义、类型、优势及应用场景,如智能客服、内容分发、电商闭环等,并介绍开发流程和工具,帮助运营者提升用户体验和效率。未来,随着微信生态的发展,公众号接口将带来更多机遇,如小程序融合、AI应用等。
|
机器学习/深度学习 人工智能 自然语言处理
指南:Grok中文版 _Grok 3 中文版本国内在线使用
Grok中文版都让用户能够不受限制地体验到最前沿的人工智能技术。通过这个平台,国内用户能够突破网络的束缚,尽情享受AI带来的便利与乐趣。
2497 4
|
API
历史上的今天免费API接口教程
该接口用于获取历史上的今天发生的事件,支持随机获取记录,数据同步自百度历史上的今天。请求方式为POST或GET,需提供用户ID和KEY,可选指定查询的具体日期。返回数据包括事件标题、年份、月份、日、关键词及百度百科链接。示例请求和响应详见文档。
905 12
|
API 数据安全/隐私保护
抖音视频,图集无水印直链解析免费API接口教程
该接口用于解析抖音视频和图集的无水印直链地址。请求地址为 `https://cn.apihz.cn/api/fun/douyin.php`,支持POST或GET请求。请求参数包括用户ID、用户KEY和视频或图集地址。返回参数包括状态码、信息提示、作者昵称、标题、视频地址、封面、图集和类型。示例请求和返回数据详见文档。
4825 1

热门文章

最新文章