H a n d s o n, p r o j e c t b a s e d
Requesting Data Using an API Call
Download 4.21 Mb. Pdf ko'rish
|
Python Crash Course, 2nd Edition
Requesting Data Using an API Call
GitHub’s API lets you request a wide range of information through API calls. To see what an API call looks like, enter the following into your browser’s address bar and press enTer : https://api.github.com/search/repositories?q=language:python&sort=stars This call returns the number of Python projects currently hosted on GitHub, as well as information about the most popular Python repositories. Let’s examine the call. The first part, https://api.github.com/ , directs the request to the part of GitHub that responds to API calls. The next part, search/repositories , tells the API to conduct a search through all reposito- ries on GitHub. The question mark after repositories signals that we’re about to pass an argument. The q stands for query, and the equal sign ( = ) lets us begin specifying a query ( q= ). By using language:python , we indicate that we want information only on repositories that have Python as the primary language. The final part, &sort=stars , sorts the projects by the number of stars they’ve been given. Working with APIs 361 The following snippet shows the first few lines of the response. { u "total_count": 3494012, v "incomplete_results": false, w "items": [ { "id": 21289110, "node_id": "MDEwOlJlcG9zaXRvcnkyMTI4OTExMA==", "name": "awesome-python", "full_name": "vinta/awesome-python", --snip-- You can see from the response that this URL is not primarily intended to be entered by humans, because it’s in a format that’s meant to be pro- cessed by a program. GitHub found 3,494,012 Python projects as of this writ- ing u. Because the value for "incomplete_results" is false , we know that the request was successful (it’s not incomplete) v. If GitHub had been unable to fully process the API request, it would have returned true here. The "items" returned are displayed in the list that follows, which contains details about the most popular Python projects on GitHub w. Download 4.21 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling