It is build with Laravel and provide a REST API to store annual leaves per user.
- Register
- Login
- User Info
- Update User Info
- Get All Leaves
- Get A Specific Leave
- Create New Leave
- Update A Leave
- Delete A Leave
Used to registered a new User.
URL : /register
Method : POST
Auth required : NO
Data constraints
{
"name": "[Full name in plain text]",
"email": "[valid email address]",
"password": "[password in plain text]",
"total_leaves": "[Total Annual Leave Days per year]"
}
Data example
{
"name": "Love Examples",
"email": "iloveauth@example.com",
"password": "abcd1234",
"total_leaves": 25
}
Code : 200 OK
Content example
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkubGVhdmVzLmNjLm5mXC9yZWdpc3RlciIsImlhdCI6MTU0ODMzOTUyOSwiZXhwIjoxNTQ4MzQzMTI5LCJuYmYiOjE1NDgzMzk1MjksImp0aSI6IjlneTZxZUJsdnVuVEtXbG4iLCJzdWIiOjIsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.eOqmBnqcnvZglMnhBeAWaKP9KdVqDx6iunewPdTBjvA",
"token_type": "bearer",
"expires_in": 3600
}
Used to collect a Token for a registered User.
URL : /login
Method : POST
Auth required : NO
Data constraints
{
"email": "[valid email address]",
"password": "[password in plain text]"
}
Data example
{
"email": "iloveauth@example.com",
"password": "abcd1234"
}
Code : 200 OK
Content example
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkubGVhdmVzLmNjLm5mXC9sb2dpbiIsImlhdCI6MTU0ODMzOTczOCwiZXhwIjoxNTQ4MzQzMzM4LCJuYmYiOjE1NDgzMzk3MzgsImp0aSI6InZvZEJPdU9PT0dHWU1SNFYiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.aK_IBxqkhFBwCE5gFSBHLAnQJLe-tJnZ3dZWCZb4vwE",
"token_type": "bearer",
"expires_in": 3600
}
Condition : If 'username' and 'password' combination is wrong.
Code : 401 UNAUTHORIZED
Content :
{
"error": "Unauthorized"
}
Used to collect info for a registered User.
URL : /user
Method : GET
Auth required : YES
Code : 200 OK
Content example
{
"id": 1,
"name": "Love Examples",
"email": "iloveauth@example.com",
"email_verified_at": null,
"total_leaves": 20,
"created_at": "2019-01-24 13:02:19",
"updated_at": "2019-01-24 13:02:19"
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Used to update info for a registered User.
URL : /user/{id}
Method : PUT
Auth required : YES
Data constraints
{
"name": "[User full name in plain text]",
"total_leaves": "[Total Annual Leave Days per year]"
}
Data example
{
"name": "Love Examples",
"total_leaves": 25
}
Code : 200 OK
Content example
{
"id": 1,
"name": "Love Examples",
"email": "iloveauth@example.com",
"total_leaves": 20,
"email_verified_at": null,
"created_at": "2019-01-25 08:29:46",
"updated_at": "2019-01-25 09:26:33"
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Condition : If id is not found.
Code : 404 NOT FOUND
Condition : If you try to update user info of another user.
Code : 403 FORBIDDEN
Content :
{
"error": "You can only edit yourself."
}
Used to collect all leaves for a registered User.
URL : /leaves
Method : GET
Auth required : YES
Code : 200 OK
Content example
{
"data": [
{
"id": 1,
"from": "2018-12-24",
"until": "2018-12-31",
"days": "4"
},
{
"id": 2,
"from": "2018-09-10",
"until": "2018-09-21",
"days": "10"
}
]
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Used to collect all leaves for a registered User.
URL : /leaves/{id}
Method : GET
Auth required : YES
Code : 200 OK
Content example
{
"data": {
"id": 1,
"from": "2018-12-24",
"until": "2018-12-31",
"days": "4"
}
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Condition : If you try to access a leave that belongs to another user.
Code : 403 FORBIDDEN
Content :
{
"error": "You can only view your own leaves."
}
Condition : If id is not found.
Code : 404 NOT FOUND
Used to create a new leave for a registered User.
URL : /leaves
Method : POST
Auth required : YES
Data constraints
{
"from": "[valid date in plain text and Y-m-d format]",
"until": "[valid date in plain text and Y-m-d format]"
}
Data example
{
"from": "2018-12-24",
"until": "2018-12-31"
}
Code : 200 OK
Content example
{
"data": {
"id": 4,
"from": "2018-12-24",
"until": "2018-12-31",
"days": 4
}
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Condition : If dates are in wrong format.
Code : 422 UNPROCESSABLE ENTITY
Content :
{
"error": "From and Until dates must be in Y-m-d format"
}
Condition : If from date is greater than until date.
Code : 422 UNPROCESSABLE ENTITY
Content :
{
"error": "From can not be greater than Until date"
}
Used to update an existing leave for a registered User.
URL : /leaves/{id}
Method : PUT
Auth required : YES
Data constraints
{
"from": "[valid date in plain text and Y-m-d format]",
"until": "[valid date in plain text and Y-m-d format]"
}
Data example
{
"from": "2018-12-27",
"until": "2018-12-30"
}
Code : 200 OK
Content example
{
"data": {
"id": 1,
"from": "2018-12-27",
"until": "2018-12-30",
"days": 2
}
}
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Condition : If dates are in wrong format.
Code : 422 UNPROCESSABLE ENTITY
Content :
{
"error": "From and Until dates must be in Y-m-d format"
}
Condition : If from date is greater than until date.
Code : 422 UNPROCESSABLE ENTITY
Content :
{
"error": "From can not be greater than Until date"
}
Condition : If id is not found.
Code : 404 NOT FOUND
Condition : If you try to update a leave that belongs to another user.
Code : 403 FORBIDDEN
Content :
{
"error": "You can only edit your own leaves."
}
Used to delete an existing leave for a registered User.
URL : /leaves/{id}
Method : DELETE
Auth required : YES
Code : 204 NO CONTENT
Condition : If bearer token is not valid.
Code : 500 INTERNAL SERVER ERROR
Condition : If id is not found.
Code : 404 NOT FOUND
Condition : If you try to delete a leave that belongs to another user.
Code : 403 FORBIDDEN
Content :
{
"error": "You can only delete your own leaves."
}