Interacting with GitHub
We will use APIs to work together with GitHub too. Conserving it easy, we’ll use the POST request to create a brand new repo known as
First, as all the time, we want an authorization token. Luckily, we are able to get this arrange a lot sooner than we did with the Google Maps API — you’ll find a step-by-step guide here.
Observe that on step seven, it’s totally as much as you which ones permissions you choose — however all we are going to want is
Now, we are able to authenticate ourselves by including
headers= to our requests.
Create a repo
To create a repo, we merely ship a POST request to
person/repos. The one required subject right here is the
identify worth, which specifies the brand new repo identify. We additionally set
true which merely units the repo privateness settings to public — relatively than non-public (the default).
Observe that we use
PAYLOAD to comprise our directions for the API, which we move to the
knowledge argument inside
requests.publish. We additionally embody our authorization key/token utilizing the
If we reach creating the repo, we are going to obtain code
201 Created — indicating that the request has succeeded, and we now have created a brand new useful resource.
We will additionally examine on GitHub, and certain sufficient the
api_test repo is true there:
The GitHub API could be very cool, there’s lots we are able to do with it, and due to that, it’s nice for studying — I’d advocate looking at the docs when you’d prefer to study extra (be happy to ask me questions too!).