- GET /users?limit=10&sort=id&order=asc
- 输出: Content-Type: application/json
[ { "id": 1, "username": "user1" }, { "id": 2, "username": "user2" }, ... ]
- POST /login
- 输入:
Content-Type: application/json
{ "username": "user1", "password": "password1" }
- 输出:
HTTP/1.1 200 OK
HTTP/1.1 401 Unauthorized
- PUT /user/:id
- 输入:
Content-Type: application/json
{ "email": "[email protected]" }
- 输出:
HTTP/1.1 200 OK
- DELETE /user/:id
- 输出:
HTTP/1.1 200 OK
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="rest.js"></script>
var methods = ['get:/users', 'post:/login', 'put:/user', 'delete:/user']; var rest = new Rest(methods); var rest = new Rest('/path', methods);//baseurl: '/path'
//获取用户信息: rest.getUsers(callback); rest.getUsers(function(status, users) { console.log(status);//200 or 401 console.log(users);//user list });
//根据条件获取用户信息: rest.getUsers(callback, params); rest.getUsers(function(status, users) { console.log(status);//200 or 401 console.log(users);//user list }, { limit: 10, sort: 'id', order: 'asc' });
//登录: rest.postLogin(callback, params); rest.postLogin(function(status, users) { console.log(status);//200 or 401 }, { username: 'user1', password: 'password1' });
//修改用户: rest.putUser(callback, id, params); rest.putUser(function(status) { console.log(status); }, 1, { email: '[email protected]' });
//删除用户: rest.deleteUser(callback, id); rest.deleteUser(function(status) { console.log(status); }, 1);
var method = ['get:/path/root/test', 'get:/path/root/hello', ]; var rest = new Rest(method); rest.path.root.getTest(function(status, data) { console.log(status, data); }); rest.path.root.getHello(function(status) { console.log(status, data); });
- 邮箱: [email protected]
- 微博: @文翼