Simple blog site API design
Foreword
This project is the work of Zhongshan University School of Science and Computer Data 2019 service computing. All the code will be uploaded to the blog github them.
Github project Address: https://github.com/StarashZero/ServerComputing/tree/master/hw6
profile: https://starashzero.github.io
About the job
Imitation Github , design a blog site API
API
Blog site using the HTTPS protocol, address the root of all requests: https://spblog.com
data transfer with JSON default form
Current version
There may be multiple versions of the site, the latest version of the default request, you can choose other versions on their own
Accept: application/vnd.spBlog.v3+json
Schema
All API via HTTPS to access, send and receive data in the form as JSON
curl -i https://spblog.com/users/articles/firstblog
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 12 Oct 2012 23:33:14 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 200 OK
ETag: "a00049ba79152d03380c34652f2cb612"
X-SpBlog-Media-Type: spblog.v3
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4987
X-RateLimit-Reset: 1350085394
Content-Length: 5
Cache-Control: max-age=0, private, must-revalidate
X-Content-Type-Options: nosniff
Authentication
To blog upload, modify need to provide account information, as well as some private blog need to get certified
- Basic authentication
here to provide a basic authentication
curl -u "username" https://spblog.com
to confirm the presence of the user will be asked to continue to enter the correct password authentication is completed, access to the corresponding authority (in this article to modify the account, upload and access private articles, etc.), otherwise404 Not Found
Articles list
Users can view all published blog, the response also comes with an overview of each blog (if it is specified, the default first paragraph)
GET /user/articles
parameters may include the following:
private | Whether to include private blog, if it is true you need certification |
max_length | The maximum number of selected blog (time sorting), not set or null means unlimited |
Example:
curl -i -uuser https://spblog.com/user/articles?private=true&max_length=10
expressed view 10 blog recently released (includes private blog)
Get article
May request a single blog post, the response will be included with the details of the blog
GET /user/articles/firstBlog/
may be accompanied by private parameters, use consistent with Articles list
Search article
Blog can search with certain features, the response will be included with all satisfy the conditions of the blog summary information
GET /user/search/
may be accompanied by the following parameters:
private | Whether to include private blog, if it is true you need certification |
max_length | The maximum number of selected blog (time sorting), not set or null means unlimited |
keyword | Looking for keywords |
in_content | Whether to search blog contents, if it is false only title search |
Example:
curl -uuser -i https://spblog.com/user/search?keyword=api&private=true&in_content=true
indicates a search contains "api" All blog
Upload article
Upload (publish) blog, the user must have been certified by the
PUT /user/upload
parameters that can be included are as follows
private | Whether it is a private article |
title | Article Title |
summary | Overview article, it defaults to the first paragraph of vacant |
content | Article Content |
Longer be uploaded parameters, the example JSON format:
curl -uuser -i -d '
{
"title":"FirstBlog",
"summary":"summary of first blog",
"content":"some words"
}
'
https://spblog.com/user/upload?private=true
Update article
May be made to the article has released an update, use the upload is similar, but must provide the ID update an existing blog, and other parameters included may overwrite the original parameters, if not included with the same
PUT /user/upload
parameters can be included as follows
id | Article id |
private | Whether it is a private article |
title | Article Title |
summary | Overview article, it defaults to the first paragraph of vacant |
content | Article Content |
Longer be uploaded parameters, the example JSON format:
curl -uuser -i
https://spblog.com/user/update?private=false&id=1
Meaning that the id of the blog changed to open 1
Delete article
Delete blog requires a user has authenticated, and provide the id number of published articles
Delete /user/delete
Example:
curl -uuser -i
https://spblog.com/user/delete?id=1
Meaning the id of the deleted blog 1