Users endpoint
User object
| Name | Type | Description |
|---|---|---|
| id | integer |
The user id |
string |
[email protected] | |
| first_name | string |
Fist name of the user |
| last_name | string |
Last name of the user |
| fullname | string |
first_name and last_name combined |
| api_key | string |
nil |
Validations
| Field | Value |
|---|---|
| first_name | Must be present |
| last_name | Must be present |
| password | Lenght must be have a minimum of 6 characters |
| password_confirmation | Must be present |
| Must be present | |
| Must be true | |
| Must be unique |
Endpoints
| URL | Description |
|---|---|
| POST api/v1/users | Register as a new user |
| POST api/v1/auth | Login as a user |
| DELETE api/v1/auth/sign_out | Logout as the current user |
POST api/v1/users
Het user endpoint geeft je een object met daarin een user
attribute. Dit ziet er als volgt uit:
[
{
"user": {
"id": 1,
"email": "[email protected]",
"first_name": "Henk",
"last_name": "Serious",
"full_name": "Henk Serious",
"api_key": null
}
}
]
Status: HTTP/1.1 201 Created
Errors:
Als email al eenmaal gebruikt is, krijg je de volgende informatie terug:
{
"email": [
"has already been taken"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
Als password te weinig characters heeft:
{
"password": [
"is too short (minimum is 6 characters)"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
Als password niet meegestuurd wordt:
{
"password": [
"can't be blank",
"is too short (minimum is 6 characters)"
],
"password_confirmation": [
"doesn't match Password"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
Als password_confirmation niet gelijk is aan password:
{
"password_confirmation": [
"doesn't match Password",
"doesn't match Password"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
Als email niet meegestuurd word:
{
"email": [
"is not a valid email address",
"can't be blank"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
Als first_name mist:
{
"first_name": [
"can't be blank"
]
}
Als last_name mist:
{
"first_name": [
"can't be blank"
]
}
Status: HTTP/1.1 422 Unprocessable Entity
POST api/v1/auth
Bij een POST naar /api/v1/auth word de gebruiker ingelogt. Hierbij moet een email-veld en een password-veld meegestuurd worden. Tijdens het inloggen krijgt de gebruiker een API Key toegewezen, zodat de gebruiker alleen bij zijn eigen data kan.
Example request
POST http://localhost:3000/api/v1/auth
email: [email protected]
password: test123
| Field | Value |
|---|---|
| test123 | [email protected] |
| password | test123 |
Example response:
Status: HTTP/1.1 202 Accepted
[
{
"user": {
"id": 1,
"email": "[email protected]",
"first_name": "Henk",
"last_name": "Serious",
"full_name": "Henk Serious",
"api_key": "L0tluWnYVKzUCHKKQZQ4xAtt"
}
}
]
Errors:
Als er geen email meegestuurd wordt, krijg je de volgende informatie terug:
{
"error": "Incorrect e-mail or password"
}
Status: HTTP/1.1 401 Unauthorized
Als er geen password meegestuurd wordt, krijg je de volgende informatie terug:
{
"error": "Incorrect e-mail or password"
}
Status: 401 Unauthorized
DELETE api/v1/auth/sign_out
Bij een DELETE naar api/v1/auth/sign_out wordt de user uit de database opgezocht op basis van de API Key die gegeven is bij het inloggen. De toegewezen API key wordt bij het uitvoeren van DELETE op nil gezet
Example request
DELETE `http://localhost:3000/api/v1/auth/sign_out`
Successfully logged out
| Field | Value |
|---|---|
| api_key | L0tluWnYVKzUCHKKQZQ4xAtt |
Example response:
Status: HTTP/1.1 HTTP/1.1 200 OK
{
"message": "Successfully logged out"
}