個人項目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)

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存儲庫的鏈接 。

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)

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。

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/

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)

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??。

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

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)

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端點進行交互的示例。

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/

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.
您還可以使用一個端點來搜索與某個關鍵字匹配的特定笑話。

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)

… this site is mean.
…這個網站是卑鄙的。
The premise is really simple: you call the API and get an insult.
前提很簡單:調用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

“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接口
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/389872.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/389872.shtml 英文地址,請注明出處:http://en.pswp.cn/news/389872.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!