Repositories
Learn and practice the functionalities of repositories in the GitHub API.
We'll cover the following...
Overview
Repositories are containers where the complete project and its files are presented on GitHub. In addition, various versions of the files also exist in that repository. The owner of the repository can be the person themselves or anyone they would like to share the ownership with. We can create branches inside a repository where each type of file can be isolated from another.
Create a repository
Instead of actually moving to the website and manually creating the repository, we can rather generate an HTTP POST
request to do so.
Request Parameters
Parameters | Type | Category | Description |
| String | Required | The name of the repository that we want to create |
| String | Optional | The repository’s description |
| String | Optional | The repository’s information URL |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
| Boolean | Optional | This is |
Let’s try creating it by using the API in the code widget below. Please provide the repository name in the widget below against the REPOSITORY
key. It'll be replaced in the code in line 9.
const endpointUrl = 'https://api.github.com/user/repos';const headers = {Authorization: 'token {{ACCESS_TOKEN}}',Accept: 'application/vnd.github.v3+json',};const body = JSON.stringify({name: '{{REPOSITORY}}',});const options = {method: 'POST',headers,body,};async function CreateRepo() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printErrors(error);}};CreateRepo();
The HTTP response of the above code can be the following:
201
: The repository has been created.403
: It is forbidden for the repository to be created....