Skip to content

API: users

luqiuyuan edited this page Jun 7, 2019 · 1 revision
VERB PATH DESC
GET /users show multiple users
GET /users/:id show an user
POST /users create an user
GET /user show the logged-in user
PATCH/PUT /user update the logged-in user
DELETE /user destroy the logged-in user

GET /users

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功
not found (404) 未找到

GET /users/:id

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功
not found (404) 未找到

POST users

request

{
  "user": {
    "email": "[email protected]",
    "password": "Ab123456",
    "name": "Dream Future",
    "avatar_url": "http://www.bigfish.com",
    "description": "Black sheep wall."
  }
}

validations

  • user (required)
    • email (required, max length 255, valid email format)
    • password (required, min length 6, max length 50, at least one upcase letter and one downcase letter)
    • name (max length 50)
    • avatar_url (max length 2000)
    • description (max length 60)

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
created (201) 创建成功
bad request (400) missing_field 缺少参数 { "code": "missing_field", "field": "user:email" }
invalid_field 参数错误 { "code": "invalid_field", "field": "user:password" }
duplicated_field 重复 { "code": "duplicated_field", "field": "user:email" }

GET /user

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功

PATCH/PUT /user

request

{
  "user": {
    "email": "[email protected]",
    "password": "Ab123456",
    "name": "Dream Future",
    "avatar_url": "http://www.bigfish.com",
    "description": "Black sheep wall."
  }
}

validations

  • user (required)
    • email (max length 255, valid email format)
    • password (min length 6, max length 50, at least one upcase letter and one downcase letter)
    • name (max length 50)
    • avatar_url (max length 2000)
    • description (max length 60)

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功
bad request (400) missing_field 缺少参数 { "code": "missing_field", "field": "user" }
invalid_field 参数错误 { "code": "invalid_field", "field": "user:password" }
duplicated_field 重复 { "code": "duplicated_field", "field": "user:email" }
not found (404) 未找到

DELETE /user

response

see view INDEX

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功

Views

SHOW

{
  "user": {
    "id": 1,
    "email": "[email protected]",
    "name": "Dream Future",
    "avatar_url": "http://www.bigfish.com",
    "description": "Black sheep wall.",
    "created_at": "2016-05-01T23:00:00.000Z",
    "updated_at": "2016-05-01T23:00:00.000Z"
  }
}