I use github issues to manage my blog’s comments and this is the background.
API server is used for creating a new issue for my blog comment.
The POSΤ request can’t sent to github from github pages because it doesn’t suppport CORS. Thus, I create an api server as a springboard.
In addition, you can find the implement of my static comments system here.
You can use this as your api server and it’s domain is:
https://blog-api-server.herokuapp.com/
If you want to use this, you need to send a GET request to the url of:
https://blog-api-server.herokuapp.com/issues
You also need to provide the data of:
title labels body owner repo auth
for example:
https://blog-api-server.herokuapp.com/issues?title=test&labels=blog&body=Welcome to leave comments here.&owner=yydai&repo=yydai.github.io&auth=<base64(username:password)>
Note: The username and password is github account.
Also, you can setup your own api server.
The endpoint is:
https://{hostname}/blog/api/v1/
The API of our service:
HTTP Method | URL | Action |
---|---|---|
GET | {endpoint}/issues | |
POST | https://api.github.com/repos/{owner}/{repo}/issues | create an issue |
GEΤ Parameters:
Name | Type | Description |
---|---|---|
title | string | Required. The title of the blog. |
labels | string | Required. Default is “blog”. |
body | string | The contents of the issue. Default is “Welcome to leave comments here.”. |
owner | string | Required. The owner of the repo. Default is “yydai” |
repo | string | Required. The repo name. Default is “yydai.github.io” |
auth | string | Required. the base64(username:password) |
Example:
{endpoint}/issues?title=This is a test&labels=blog&body=Welcome to leave comments here.&owner=yydai&repo=yydai.github.io
POSΤ Parameters:
Name | Type | Description |
---|---|---|
title | string | Required. The title of the issue. |
labels | string | Required. Label to associate with this issue. |
body | string | The contents of the issue. |
Example:
https://api.github.com/repos/yydai/yydai.github.io/issues { "title": "This is a test", "body": "Welcome to leave comments here.", "labels": ["blog"] }
I will use Flask to do this job. tutorials1 and tutorials2.
In this phase, Our goal is just to implement the api above.
You can view the code in app.py.
I will use the Heroku to deploy this api server.
If you want to use Heroku to deploy flask application, you need to include the following files:
- Procfile
- requirements.txt
Check the documentation of Python here if necessary.
Using the following command to get the requirements.txt.
pip freeze > requirements.txt
In this project, my Procfile:
web gunicorn <app>:app