GET AND PUT To Github API using Postman

Rabu, 12 Juli 2023 19:34:56 oleh Wahyudi

github-postman
In this case, actually i have an idea to CRUD data into JSON file. I use nextjs framework hosting on vercel and push data via github. For http request, i use postman
Make Github Token
The first before all, we need a token from github. You can get it by your github account, setting, and click developer setting . Then go to Personal Acces Token-Token(clasic)-Generate New Token. Personal access tokens (classic) function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS, or can be used to authenticate to the API over Basic Authentication.
Then, fill the Note (What is your token for), set expiration, and select scope. In this case, i select all scope. Finally, Generate Token and copy the token carefully because it appear once.
Test In Postman
I hope you had installed postman in your divice, and create new collection. We need two method to up date data in our github via postman, GET and PUT. We use Endpoints available for GitHub App user access tokens, GET /repos/{owner}/{repo}/contents/{path}.
Replace {owner} with your account name, {repo} with your repository name, {path} with path your file exist.
First, we want to request by using GET method. In this method set the Authorization to basic auth, and no need body. Use your github token for Authorize and then send the request. We will use data sha to PUT request
Next, we use PUT method to update all data contents in your file. Remember when using PUT method, it mean we replace all data with new data. Use same authorize like GET and set the body to json contain object message, content and sha. Message is information to our commit, while content is our data will be inserted. Remember to change or encode the content to base64. This link will help you to do it Base64Encode. While sha is last condition of our commit must updated continuesly. Finaly, by send the request , our data in github will automaticly up dated, in vercel to.

Komentar