本站 API
后期希望添加的功能
- [ ] 网盘功能
将导航栏的 WATERLAW 改为网盘功能
- [x] 增加 API 文档
提供 API 给用户使用
- [ ] 提供博客备份
用户可以下载 HTML、PDF 文章模板
- [ ] 博客样式
包括文章预览功能和各种侧边栏的样式、博客分页功能完善,
- [ ] 文章预览功能
-
[ ] 各种侧边栏的样式
-
[x] 博客分页功能
-
[ ] 将分类移至导航栏上方, 标签可考虑放在下方
-
[ ] 关于注册
考虑取消手机注册功能
- [x] 更换域名
已更换 .top 域名
API 接口
接口前缀为 /api/v1,
使用 TokenAuthentication 认证#rest_framework.authentication.TokenAuthentication
""" Simple token based authentication. Clients should authenticate by passing the token key in the "Authorization" HTTP header, prepended with the string "Token ". For example: Authorization: Token 401f7ac837da42b97f613d789819ff93537bee6a """
获取 token
获取/刷新 token
POST /api/v1/api-token/
参数 | 类型 | 是否必须 |
---|---|---|
username | String | 是 |
password | String | 是 |
获取 token 后, 只需要在请求头设置 Authorization: Token [Token 值], 举个例子, 使用 /api/v1/api-token/ 获得 Token 值为 c365048181cb536d6c54150f6965ad532b155650, 则在 http 请求头 header 要包含以下信息:
Content-Type:application/x-www-form-urlencoded Authorization:Token c365048181cb536d6c54150f6965ad532b155650
下次即可这样请求。
注册接口
无需 token 认证
POST accounts/register
参数 | 类型 | 是否必须 |
---|---|---|
username | String | 是 |
password | String | 是 |
password1 | String | 是 |
发表文章
POST articles/publish
参数 | 类型 | 是否必须 | 说明 |
---|---|---|---|
category | Int | 是 | 文章分类 |
tags | String | 是 | 文章所属标签,多个值如 [12, 23] |
title | String | 是 | 文章标题 |
body | String | 是 | 文章内容 |
获取用户下的文章
GET articles/
获取指定 id 的文章
GET articles/2
按月归档文章
GET archives/2012/09
分类文章
GET categories/2
按标签归档文章
GET tags/3
CURL
curl -d "username=lixiaofeng&password=lixiaofeng" http://localhost:8000/api/v1/api-token/
{"token":"852afb530d1c365b371e2ada44e8d758ec9c4794"}
GET
curl -H "Authorization:Token 852afb530d1c365b371e2ada44e8d758ec9c4794" http://127.0.0.1:8000/api/v1/articles/1
POST
curl -H "Authorization:Token 852afb530d1c365b371e2ada44e8d758ec9c4794" -d "category=1&tags=1&title=文章&body=this" http://127.0.0.1:8000/api/v1/articles/publish
Postman
POST http://localhost:8000/api/v1/api-token/
Body --- 格式 x-www-form-urlencoded
username:zjp password:zjp
返回一个 token
{ "token": "852afb530d1c365b371e2ada44e8d758ec9c4794" }
拿到 token, 然后设置 Header 的 Key 值 Authorization , value 值
Token 852afb530d1c365b371e2ada44e8d758ec9c4794
发表评论
评论列表, 共 0 条评论