使用Pyhon
、Flask
框架,实现RESTful api
服务器端。
服务端已经部署,地址为
api.chih.me
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"username":"test","nickname":"查尔斯","password":"python","sha1":"xxxxxxxxxxxxx","type":"student", "about":"who am I"}' http://api.chih.me/snail/api/v0.1/users
通过POST
传送json
(数据类型待完善)(通过已有密码或token保护)
成功返回json格式用户名,错误返回处理后json格式的400 {'error': 'Bad Request'}
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/users
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/users/username
$ curl -u miguel:python -i -X PUT -H "Content-Type: application/json" -d '{"username":"test","nickname":"查尔斯","password":"python","sha1":"xxxxxxxxxxxxx","type":"student", "about":"who am I"}' http://api.chih.me/snail/api/v0.1/users
JSON为新的用户信息,username与原用户相同。
$ curl -u curl -u miguel:python -i -X DELETE -H "Content-Type: application/json" -d '{"username":"test"}' http://api.chih.me/snail/api/v0.1/users
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/ok
指定用户、密码,验证通过则返回{'isok': 'ok!'}
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/token
指定用户密码GET http://api.chih.me//snail/api/v0.1/token
返回token
$ curl -u TOKEN -i -X GET http://api.chih.me/snail/api/v0.1/users
指定用户为token,密码为空获取资源,token有有效期,为十分钟
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"comp_id":"1","user_id":"1","sha1":"xxxxxxxxxxxxx","title":"test","content":"gggggggggggggggggggggg"}' http://api.chih.me/snail/api/v0.1/queses
注意:问题类型为已存在
的公司类型
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/queses
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/queses/1
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"comp_id":"1"}' http://api.chih.me/snail/api/v0.1/quesesofcomp_[hot|new]
$ curl -u miguel:python -i -X PUT -H "Content-Type: application/json" -d '{"ques_id":"1","comp_id":"1","user_id":"1","sha1":"xxxxxxxxxxxxx","title":"test","content":"gggggggggggggggggggggg"}' http://api.chih.me/snail/api/v0.1/queses
ques_id为需修改的问题id
$ curl -u miguel:python -i -X DELETE -H "Content-Type: application/json" -d '{"ques_id":"1"}' http://api.chih.me/snail/api/v0.1/queses
ques_id为需修改的问题id
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/answers
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/answer/1
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"ques_id":"5","user_id":"4","number":"3","sha1":"xxxxxxxxxxxxx","content":"gggggggggggggggggggggg"}' http://api.chih.me/snail/api/v0.1/answers
ques_id,user_id必须已经存在
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"ques_id":"1"}' http://api.chih.me/snail/api/v0.1/answersofques_[hot|new]
$ curl -u miguel:python -i -X PUT -H "Content-Type: application/json" -d '{"answer_id":"1","ques_id":"5","user_id":"4","number":"3","sha1":"xxxxxxxxxxxxx","content":"gggggggggggggggggggggg"}' http://api.chih.me/snail/api/v0.1/answers
answer_id为需修改的答案id
$ curl -u miguel:python -i -X DELETE -H "Content-Type: application/json" -d '{"answer_id":"1"}' http://api.chih.me/snail/api/v0.1/answers
answer_id为需修改的答案id
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"type":"计算机","name":"阿里巴巴"}' http://api.chih.me/snail/api/v0.1/comps
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/comps
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/comps/1
$ curl -u miguel:python -i -X PUT -H "Content-Type: application/json" -d '{"comp_id":"7","type":"计算机","name":"阿里巴巴"}' http://api.chih.me/snail/api/v0.1/comps
comp_id为需修改的公司id
$ curl -u miguel:python -i -X DELETE -H "Content-Type: application/json" -d '{"comp_id":"7"}' http://api.chih.me/snail/api/v0.1/comps
comp_id为需修改的公司id
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/practices
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/practice/1
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"title":"title","office":"职位","type":"type","comp_id":"comp_id","comp_size":"comp_size","addr":"addr","money":"money","ask":"要求","duty":"职责"}' http://api.chih.me/snail/api/v0.1/practices
comp_id必须已经存在
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"comp_id":"1"}' http://api.chih.me/snail/api/v0.1/practicesofcomp
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"practice_id":"1","title":"title","office":"职位","type":"type","comp_id":"comp_id","comp_size":"comp_size","addr":"addr","money":"money","ask":"要求","duty":"职责"}' http://api.chih.me/snail/api/v0.1/practices
practice_id为需修改的实习信息id
$ curl -u miguel:python -i -X POST -H "Content-Type: application/json" -d '{"practice_id":"1"}' http://api.chih.me/snail/api/v0.1/practices
practice_id为需修改的实习信息id
表单
<form action='/snail/api/v0.1/upload' method='post' enctype='multipart/form-data'>
<input type='file' name='uploaded_file'>
返回图片sha1
{
"sha1": "72e61b143f989fcfb12b01be71eeda18c210a135"
}
$ curl -u miguel:python -i -X GET http://api.chih.me/snail/api/v0.1/pic/sha1