Skip to content

Users#

You must be authenticated to use this resource.

Create a new user#

POST /users/

Request#

1
2
3
4
5
6
7
curl -X "POST" "http://0.0.0.0:8000/users/" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
           "username": "user-1",
           "password": "secret"
         }'

Response#

1
{"message": "User created successfully"}
1
{"message": "Unauthorized."}
1
{"message": "The username isn't available. Please try another."}

Get all users#

GET /users/

Request#

1
2
curl "http://0.0.0.0:8000/users/" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'

Response#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[
  {
    "id": 1,
    "username": "user-1",
    "admin": true,
  },
  {
    "id": 2,
    "username": "user-2",
    "admin": false,
  }
]
1
{"message": "Unauthorized."}

Get user by id#

GET /users/{id}

Request#

1
2
curl "http://0.0.0.0:8000/users/1" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'

Response#

1
2
3
4
5
{
  "id": 1,
  "username": "user-1",
  "admin": true,
}
1
{"message": "Unauthorized."}
1
{"message": "User not found"}

Update user#

PUT /users/{id}

Request#

1
2
3
4
5
6
7
curl -X "PUT" "http://0.0.0.0:8000/users/1" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
            "username": "user",
            "password": "secret"
          }'

Response#

1
{"message": "User update successfully."}
1
{"message": "Unauthorized."}
1
{"message": "User not found."}
1
{"message": "The username isn't available. Please try another."}

Delete user#

DELETE /users/{id}

Request#

1
2
curl "http://0.0.0.0:8000/users/1" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'

Response#

1
{"message": "User deleted successfully."}
1
{"message": "Unauthorized."}
1
{"message": "User not found."}

User data#

Field Type Description
name String Username.
password String Password.