Accounts and users

The following endpoints can be used to manage your account.

Register

Register an account and returns JWT informations.

$ POST /api/v1/auth/register

Request

Query Parameters :

Name Rules Description
name required|alpha_dash|max:255 Your name
email required|email|max:255|unique:users Your email
password required|string|min:6|confirmed Your password

Example :

{
    "name": "Anakin",
    "email": "darthvader@deathstar.ds",
    "password": "4nak1n",
    "password_confirmation": "4nak1n"
}

Responses

Success

Status: 200 OK

Example :

{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
    "token_type": "bearer",
    "expires_in": "86400",
    "user_id": 1
}

Error

Status: 422 Unprocessable Entity

Example :

{
    "message": "The given data was invalid.",
    "errors": {
        "password": [
            "The password field is required."
        ]
    }
}

Login

Login an account and returns JWT information.

$ POST /api/v1/auth/login

Request

Query Parameters :

Name Rules Description
email required|email Your name
password required|string Your password

Example :

{
    "email": "darthvader@deathstar.ds",
    "password": "4nak1n"
}

Responses

Success

Status: 200 OK

Example :

{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
    "token_type": "bearer",
    "expires_in": "86400",
    "user_id": 1
}

Error

Status: 401 Unauthorized

Example :

{
    "errors": {
        "email": [
            "These credentials do not match our records."
        ]
    }
}

Error

Status: 422 Unprocessable Entity

Example :

{
    "message": "The given data was invalid.",
    "errors": {
        "password": [
            "The password field is required."
        ]
    }
}

Logout

Log the user out - which will invalidate the current token and unset the authenticated user.

$ DELETE /api/v1/auth/logout

Responses

Success

Status: 200 OK

Example :

{
    "message": "Successfully logged out"
}

Error

Status: 401 Unauthorized

Example :

{
    "message": "Unauthenticated."
}

Me

Returns informations about the authenticated user.

$ GET /api/v1/auth/me

Responses

Success

Status: 200 OK

Example :

{
    "data": {
        "id": 1,
        "name": "Anakin",
        "email": "darthvader@deathstar.ds"
    }
}

Error

Status: 401 Unauthorized

Example :

{
    "message": "Unauthenticated."
}

Refresh token

Refresh a token, which invalidates the current one

$ POST /api/v1/auth/refresh

Responses

Success

Status: 200 OK

Example :

{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
    "token_type": "bearer",
    "expires_in": "86400",
    "user_id": 1
}

Error

Status: 401 Unauthorized

Example :

{
    "message": "Unauthenticated."
}

Update your account

Update and returns an user. You can only update your own account.

Params are optionals and fields won't be updated if the params are undefined.

$ PATCH|PUT /api/v1/users/:id

Request

Query Parameters :

Name Rules Description
name alpha_dash|max:255 Your name
email email|max:255|unique:users Your email
current_password required_with:password Your current password
password string|min:6|confirmed Your new password

Example :

{
    "name": "Ben",
    "email": "ben@kenobi.jo",
    "current_password": "4nak1n",
    "password": "4_n3w_h0p3",
    "password_confirmation": "4_n3w_h0p3"
}

Responses

Success

Status: 200 OK

Example :

{
    "data": {
        "id": 1,
        "name": "Ben",
        "email": "ben@kenobi.jo"
    }
}

Error

Status: 401 Unauthorized

Example :

{
    "message": "Unauthenticated."
}

Error

Status: 403 Forbidden

Example :

{
    "message": "This action is unauthorized."
}

Error

Status: 422 Unprocessable Entity

Example :

{
    "message": "The given data was invalid.",
    "errors": {
        "current_password": [
            "The current password field is required when password is present."
        ],
        "password": [
            "The password confirmation does not match."
        ]
    }
}

Error

Status: 404 Not Found

Example :

{
    "message": "No query results for model [App\\Models\\User]."
}

Delete your account

Deleting your account will also delete your tasks.

$ DELETE /api/v1/users/:id

Responses

Success

Status: 204 No Content

Error

Status: 401 Unauthorized

Example :

{
    "message": "Unauthenticated."
}

Error

Status: 403 Forbidden

Example :

{
    "message": "This action is unauthorized."
}

Error

Status: 404 Not Found

Example :

{
    "message": "No query results for model [App\\Models\\User]."
}
Last Updated: 6/22/2018, 7:08:36 AM