个人项目api接口_5个免费有趣的API,可用于学习个人项目等

个人项目api接口

Public APIs are awesome!

公共API很棒!

There are over 50 pieces covering APIs on just the Towards Data Science publication, so I won’t go into too lengthy of an introduction. APIs basically let you interact with some tool or service (which could be provided by literally anybody).

仅在Towards Data Science出版物上有50余篇关于API的文章,因此我不会过多地介绍它。 API基本上使您可以与某些工具或服务进行交互(实际上任何人都可以提供)。

You can use APIs to do retrieve some kind of information from a data source and then use it in your own script or application. Public (open) APIs are great because they allow any third-party developer to build something that can connect to an existing service.

您可以使用API​​从数据源中检索某种信息,然后在您自己的脚本或应用程序中使用它。 公共(开放)API很棒,因为它们允许任何第三方开发人员构建可以连接到现有服务的东西。

There are popular APIs to do “serious stuff” like track time-series stock data or provide updates on air quality. We won’t be touching those in this piece, as I wanted to share some fun APIs you can experiment on while you’re learning to interact with an API or even create one.

有流行的API可以执行“严重的任务”,例如跟踪时间序列的库存数据提供空气质量的更新 。 在本文中,我们将不涉及这些内容,因为我想分享一些有趣的API,您可以在学习与API交互甚至创建API时进行试验。

You could even build a simple personal project with one of these, to learn how to connect an application to an API from whichever language you’re currently learning.

您甚至可以使用其中之一来构建一个简单的个人项目,以学习如何使用您当前正在学习的任何语言将应用程序连接到API。

Let’s get to it!

让我们开始吧!

1. PlaceGOAT —山羊的免费随机照片 (1. PlaceGOAT — Free random pictures of goats)

Image for post
Holy crap it’s a goat generated by PlaceGoat
天哪,这是 PlaceGoat产生的山羊

I thought I’d kick things off with an adorable baby goat.

我以为我会和一只可爱的小山羊拉开序幕。

This is a really simple GET API where you can generate pictures of goats. I wish I had more to say but that’s really it. Here are links to the main site and the Github repository.

这是一个非常简单的GET API,您可以在其中生成山羊的图片。 我希望我有更多话要说,但是确实如此。 这里是主站点Github存储库的链接

Image for post
PlaceGOAT main site PlaceGOAT主站点

You can specify the width and the height in pixels of the image you want to generate like this:

您可以像这样指定要生成的图像的宽度和高度(以像素为单位):

http://placegoat.com/width/height

If you’re just looking to test out the requests library in Python, this would be a great place to start. If you need an idea, try writing a script to get a daily goat image and send it to your significant other (or your mom) every morning to remind them of how much you care about them. It’ll be a better version of breakfast in bed.

如果您只是想在Python中测试requests库,那么这将是一个不错的起点。 如果您需要一个主意,请尝试编写脚本以获取每日的山羊图像,并将其每天早上发送给您的重要其他人(或您的母亲),以提醒他们您对它们的关心程度。 这将是床上早餐的更好版本。

2.PokéApi—主要游戏的Pokémon数据库 (2. PokéApi — Pokémon database for main games)

Image for post
PokéApi main page PokéApi主页

Pokémon! Gotta *GET ’em all, Pokémon!

神奇宝贝! 一定要把它们全部拿来,神奇宝贝!

The RESTful PokéApi is free to use and allows you to GET information from a comprehensive database on everything from the Pokémon games, from the first Red and Blue releases until Sword and Shield.

RESTfulPokéApi是免费使用的,并允许您从全面的数据库中获取有关Pokémon游戏,从第一个Red和Blue版本到Sword和Shield的所有内容的信息。

The database is really extensive. You can get anything from a Pokémon’s abilities to evolution triggers to berry firmness. Check out the PokéApi main site and the documentation directly for more information. If you’re interested in a language-specific wrapper, check the Wrapper Libraries section. For example, you could install the Pokebase Python interface for use directly in your Python scripts, instead of having to call the API with the requests library.

该数据库确实非常广泛。 从神奇宝贝的能力到进化的触发力到浆果的坚韧性,您都能得到任何东西。 直接查看PokéApi主站点文档以获取更多信息。 如果您对特定于语言的包装感兴趣,请查看包装器库部分 。 例如,您可以安装Pokebase Python接口以直接在Python脚本中使用,而不必使用requests库调用API。

Image for post
PokéApi docs PokéApi文档

I didn’t know berries could be categorized by firmness. I wanted to find out more, so I followed this link:

我不知道浆果可以按硬度分类。 我想了解更多信息,所以我点击了此链接:

https://pokeapi.co/api/v2/berry-firmness/
Image for post
berry firmness results 浆果硬度结果

Normally, when you call an API endpoint, you should also supply an ID or name to retrieve the information for a specific data point. With the PokéApi, they say that if you call an endpoint without an ID or name, you’ll get a default list of up to 20 resources available for the API. In this case, there are 5 possible results for the “berry firmness” endpoint, so you see all of them returned in JSON format when you call the link above.

通常,在调用API端点时,还应提供ID或名称以检索特定数据点的信息。 他们说,使用PokéApi,如果您调用没有ID或名称的端点,则将获得默认的列表,其中包含多达20个可用于该API的资源。 在这种情况下,“浆果硬度”端点有5种可能的结果,因此,当您调用上面的链接时,您会看到所有结果均以JSON格式返回。

It’s a good time to note that when you’re using fully open APIs, you should be mindful of how often you’re calling a service’s endpoints. The PokéApi removed its rate limiting (API configuration of how many requests can be made per time interval), but it still reminds users to limit how frequent their requests are to keep the hosting costs low. In their fair use policy, they say that people should locally cache requested resources and that DDoS attacks will result in a permanent IP address ban. Be responsible!

现在是要注意的好时机,当您使用完全开放的API时,应注意调用服务端点的频率。 PokéApi取消了速率限制(API配置,每个时间间隔可以发出多少请求),但它仍提醒用户限制其请求的频率以保持较低的托管成本。 他们说,在合理使用政策中,人们应该在本地缓存请求的资源,而DDoS攻击将导致永久性的IP地址禁止。 要负责任!

3. Rick and Morty API-Rick and Morty的角色,位置等 (3. The Rick and Morty API — Characters, locations, and more from Rick and Morty)

Image for post
The Rick and Morty API main site Rick and Morty API主站点

Rick and Morty!

瑞克和莫蒂!

This API is RESTful and allows you to use GraphQL to query it. They also conveniently link you to the GraphQL docs if you’re new to the query language. You can use the API by making GET requests for metadata on characters, locations, and episodes from the show.

该API是RESTful的,允许您使用GraphQL对其进行查询。 如果您是查询语言的新手,它们还可以方便地将您链接到GraphQL文档 。 您可以通过对节目中角色,位置和剧集的元数据发出GET请求来使用API​​。

Image for post
The Rick and Morty API docs Rick and Morty API文档

To get information about a character from the show, you should supply their ID to the character endpoint like this:

要从演出中获取有关角色的信息,您应该像这样向角色端点提供其ID:

https://rickandmortyapi.com/api/character/5
Image for post
Jerry Smith results Jerry Smith结果

Here, supplying “5” gives us the character information on Jerry Smith. You also see at the end an associated image of the character, so if you’re looking to practice downloading files from an API, this might be a good place to start.

在这里,提供“ 5”会给我们有关杰里·史密斯的角色信息。 您还将在最后看到该字符的关联图像,因此,如果您希望练习从API下载文件,那么这可能是一个不错的起点。

Check out the main site and the documentation for more information. There are also a bunch of wrapper libraries by several authors for different languages, so check those out if you‘d rather use those. The Python implementation for it can be found here. Also, if you know some JavaScript and are interested in contributing to an open-source project, you can check out The Rick and Morty API Github.

查看主站点文档以获取更多信息。 还有一些由不同语言的作者组成的包装器库 ,因此请检查是否需要使用它们。 可以在这里找到它的Python实现。 另外,如果您知道一些JavaScript并有兴趣为开源项目做贡献,则可以查看The Rick and Morty API Github

4. icanhazdadjoke-爸爸笑话数据库 (4. icanhazdadjoke — Dad Jokes Database)

Image for post
icanhazdadjokes main site icanhazdadjokes主站点

Who doesn’t like dad jokes?

谁不喜欢爸爸的笑话?

I’m not sure if my API-related puns so far count, but I definitely love all sorts of “bad” jokes.

我不确定到目前为止与我的API相关的双关语是否有用,但是我绝对喜欢各种“坏”笑话。

You can use the icanhazdadjoke API to fetch a dad joke from the service. The API documentation gives examples of how you can interact with the API’s endpoints with curl.

您可以使用icanhazdadjoke API从服务中获取爸爸的笑话。 API文档提供了有关如何使用curl与API端点进行交互的示例。

Image for post
icanhazdadjokes API documentation icanhazdadjokes API文档

curl is a neat tool you can use from your terminal to transfer data to or from a server. In this case, you could test it out by using HTTP to GET a specific URL. For example, you could try the following in your terminal:

curl是一个很好的工具,您可以从终端使用它来与服务器之间传输数据。 在这种情况下,您可以使用HTTP来获取特定的URL进行测试。 例如,您可以在终端中尝试以下操作:

curl -H "Accept: text/plain" https://icanhazdadjoke.com/
Image for post
icanhazdadjoke curl output
icanhazdadjoke卷曲输出

The -H command-line argument allows you to include one parameter, which in this case is “Accept: text/plain”, of an extra header in the request. This modification allows you to specify the type of output from your request, which here will just be plaintext. You could also set it to JSON (Accept: text/html) or HTML (Accept: Application/json) if that’s what you need.

-H命令行参数允许您在请求中包含一个额外头的参数,在本例中为“ Accept:text / plain”。 通过此修改,您可以指定请求的输出类型,此处只是纯文本。 如果需要,还可以将其设置为JSON( Accept: text/html )或HTML( Accept: Application/json )。

There’s also an endpoint you can use to search for specific jokes that match a certain keyword.

您还可以使用一个端点来搜索与某个关键字匹配的特定笑话。

Image for post
icanhazdadjoke API documentation icanhazdadjoke API文档

It could be interesting to practice searching for a few keywords by calling this endpoint and storing the results in a database. Then you’d have a local copy of jokes based on the keywords you specified.

通过调用此端点并将结果存储在数据库中来练习搜索一些关键字可能会很有趣。 然后,您将根据指定的关键字获得本地笑话副本。

Check out the main site and the documentation for more information. There’s also a GraphQL query endpoint you can use to query the API if you want to load data that way.

查看主站点文档以获取更多信息。 如果要以这种方式加载数据,还可以使用GraphQL查询端点来查询API。

5.邪恶的侮辱产生者-均值数据库 (5. Evil Insult Generator — A Mean Database)

Image for post
Evil Insult Generator main site 邪恶侮辱生成器主站点

… this site is mean.

…这个网站是卑鄙的。

The premise is really simple: you call the API and get an insult.

前提很简单:调用API并侮辱他人。

Image for post
Evil Insult Generator API documentation Evil Insult Generator API文档

Just like the goat API, I don’t really have that much to say here.

就像山羊API一样,我在这里没有太多要说的。

You can specify the language and the format of how you want the insult to be returned. For fun, I wanted to see if another language would actually work, so I tried to get a Spanish insult:

您可以指定希望如何返回侮辱的语言和格式。 为了娱乐,我想看看另一种语言是否真的可以工作,所以我试图受到西班牙的侮辱:

https://evilinsult.com/generate_insult.php?lang=es&type=json
Image for post
Result of Evil Insult Generator API call 邪恶侮辱生成器API调用的结果

“Mala leche” translates literally to English as “bad milk”. Colloquially, you use it to describe someone that acts in bad faith or someone who’s in a bad mood.

“ Mala leche”字面意思是“坏牛奶”。 口语化地,您可以用它来形容表现出恶意的人情绪低落的人。

You can also use this API as a really simple one to practice making requests with. Check out the main site and its (rather simple) documentation if you want to explore.

您还可以将此API用作练习请求的一种非常简单的方法。 如果要浏览,请查看主站点及其(相当简单的) 文档

And that’s all!

就这样!

I hope you try working with one of these as you start familiarizing yourself with APIs or if you’re just looking for something fun to work with. Be sure to call the APIs responsibly, as these are public and meant to be consumed by everyone without charge. Pinging them too frequently can lead to your IP address being banned, which if you love goat pictures (or whatever service yo’re using) will not be a good thing.

我希望您在开始熟悉API或只是在寻找有趣的东西时尝试使用其中之一。 确保以负责任的方式调用这些API,因为这些API是公开的,并且每个人都可以免费使用。 过于频繁地对它们进行ping操作可能会导致您的IP地址被禁止,如果您喜欢山羊图片(或您使用的任何服务),那将不是一件好事。

Besides just calling GET requests, I mentioned that storing results might make for an interesting addition to your project, so check out this piece if you want to see how you can write to SQLite:

除了仅调用GET请求外,我还提到存储结果可能会对您的项目产生有趣的影响,因此如果您想了解如何写入SQLite,请查看以下内容:

For a completely different way of collecting data online, check out this piece on an introduction to the XPath language and its usage with Python:

对于一种完全不同的在线收集数据的方式,请查看关于XPath语言及其在Python中的用法的介绍:

翻译自: https://towardsdatascience.com/5-free-and-fun-apis-to-use-for-learning-personal-projects-and-more-1cb37b0d3685

个人项目api接口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值