Github REST API for Gists

Create a Gist

Method: POST

PATH: /gists

JSON Data: {"description":"Example of a gist","public":false,"files":{"sample.md":{"content":"Hello World"}}}

Response Status Code On Success: 201

Example Response:

{
  "url": "https://api.github.com/gists/2decf6c462d9b4418f2",
  "forks_url": "https://api.github.com/gists/2decf6c462d9b4418f2/forks",
  "commits_url": "https://api.github.com/gists/2decf6c462d9b4418f2/commits",
  "id": "2decf6c462d9b4418f2",
  ...

Curl

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/gists \
  -d '{"description":"Example of a gist","public":false,"files":{"sample.md":{"content":"Hello World"}}}'

Read a Gist

Method: GET

PATH: /gists/{gist_id}

Response Status Code On Success: 200

Example Response:

{
  "url": "https://api.github.com/gists/2decf6c462d9b4418f2",
  "forks_url": "https://api.github.com/gists/2decf6c462d9b4418f2/forks",
  "commits_url": "https://api.github.com/gists/2decf6c462d9b4418f2/commits",
  "id": "2decf6c462d9b4418f2",
  ...

Response Status Code On Resouce Not Found: 404

Curl

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/gists/GIST_ID

Update a Gist

Method: PATCH

PATH: /gists/{gist_id}

Response Status Code On Success: 200

Example Response:

{
  "url": "https://api.github.com/gists/2decf6c462d9b4418f2",
  "forks_url": "https://api.github.com/gists/2decf6c462d9b4418f2/forks",
  "commits_url": "https://api.github.com/gists/2decf6c462d9b4418f2/commits",
  "id": "2decf6c462d9b4418f2",
  ...

Response Status Code On Resouce Not Found: 404

Curl

curl -L \
  -X PATCH \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/gists/GIST_ID \
  -d '{"description":"An updated gist description","files":{"sample.md":{"content":"Hello World from GitHub"}}}'

Delete a Gist

Method: DELETE

PATH: /gists/{gist_id}

Response Status Code On Success: 200

Example Response: No return Data

Response Status Code On Resouce Not Found: 404

Curl

curl -L \
  -X DELETE \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/gists/GIST_ID

See reference