用户管理

2017-02-21  本文已影响0人  SetZero

用户管理


1、获取所有用户信息

  • 需要用户授权验证
GET /api/users
curl -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users"
Status: 200 OK
Content-Type: application/json
[
  {
    "id": 1,
    "login": "adminuser",
    "email": "ziling.zhong@hand-china.com",
    "avatar_url": "https://secure.gravatar.com/avatar/0f656b0b09d16bafa95064e7e9bd83bc",
    "active": false
  },
  {
    "id": 2,
    "login": "zzl",
    "email": "zhongziling@vip.qq.com",
    "avatar_url": "https://secure.gravatar.com/avatar/8395226d8e9a44caa3369a541d65e576",
    "active": false
  }
]

2、获取指定用户信息

  • 获取指定用户信息需要查询的用户名。
  • 需要用户授权验证。
GET /api/users/{login}
curl -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users/zzl"
Status: 200 OK
Content-Type: application/json
{
  "id": 2,
  "login": "zzl",
  "email": "zhongziling@vip.qq.com",
  "avatar_url": "https://secure.gravatar.com/avatar/8395226d8e9a44caa3369a541d65e576",
  "active": false
}

3、创建用户

  • 创建一个新的账户,并返回该用户的详细信息。
  • 需要用户授权验证。
POST /api/users/{login}
{
  "login": "hand",
  "email": "hand@github.com",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "admin": false,
  "active": true
}
curl -X POST -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" -H "Content-Type: application/json" -d '{
  "login": "hand",
  "email": "hand@github.com",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "admin": false,
  "active": true
}' "http://192.168.58.13/api/users"
Status: 200 OK
Content-Type: application/json
{
  "id": 3,
  "login": "hand",
  "email": "hand@github.com",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "active": true
}

4、更新用户信息

  • 更新一个已存在的用户的信息。
PATCH /api/users/{login}
{
  "email": "hand@hand.com",
  "admin": ture,
  "active": false
}
curl -X PATCH -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" -H "Content-Type: application/json" -d '{
  "email": "hand@hand.com",
  "admin": true,
  "active": false
}' "http://192.168.58.13/api/users/hand"
Status: 200 OK
Content-Type: application/json; charset=utf-8
{
  "id": 3,
  "login": "hand",
  "email": "hand@github.com",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "active": false
}

5、删除指定用户

  • 删除指定用户。
DELETE /api/users/{login}
curl -X DELETE -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users/hand"
Status: 200 OK
Content-Type: text/plain; charset=utf-8
上一篇 下一篇

猜你喜欢

热点阅读