Overview
Usually a plugin site or an extension store has features allowing users to comment and rate a specific item. This kind of interactive feature requires a backend to provide data dynamically. Normally, for dynamic sites, they can use their own API and backend to do that. But for static websites like Plugin Website for Joplin, we have to borrow the power from an existing API provider such as Github API or Discourse API.
The general idea is that, when a user visits the website, the website will send an asynchronize request to the API to pull data dynamically. And when a user writes a comment or submits a rating to a plugin, the website will create a request to the API to update the data.
UPDATE:
After further investigating how other static websites(like blogs, product promotion sites, etc)(example) did, I found that most of them only display the comments. And you have to go to places like GitHub issues or the forum to post a new comment.
I think this makes sense since it's dangerous to let users put content directly from front-end without an authorization system. And for these two APIs, you have to have a API KEY to post thing to it which can be dangerous if we coded it into the front-end without proper permission control, too.
So maybe embed the Discourse Comment Embeds into the website is the better way for us now.
Original Content
Choice of API
Potentially, I have two options in my mind. The first one is the Github API. Github API has the power to perform CRUD operations on repos, issues, gists and etc. For example, we can store the comments and rating data inside a gist, and using Github API to retrieve and update these data.
To get a gist simply send a GET request to /gists/{gist_id}
endpoint. It will return the file in files
field. And to update a gist, send a PATCH request to /gists/{gist_id}
with a body contains the file.
The downside of using Github API is that
- It has limitations on requests per hour. For anonymous users, it is 60 times per hour. And for authorized users, it is 5000 times per hour.
- It might be unstable for users in specific regions, like China.
The second one is Discourse API. The idea is basically the same as the Github API, the difference is we are creating a post in this forum to keep track all the data.
We can retrieve post from https://{defaultHost}/posts/{id}.json
and update post by sending a PUT to https://{defaultHost}/posts/{id}.json
.
There are also downsides to this one:
- API key required, it is generated from the admin pane. I don't know if there is permission control on this, if not then it might be dangerous to use this API on the front end.
Let me know if you know better ways to implement interactive components on a static website. Any discussion is appreciated!