The Drink Manager API allows to manage drinks. It uses the HTTP protocol on port 8080
.
The JSON format is used to exchange data. The Content-Type
header must be set
to application/json
when sending data to the API. The Accept
header must be
set to application/json
when receiving data from the API.
The API is based on the CRUD pattern. It has the following operations:
Auth
- Login
- Logout
- Create manager
- List manager
- Delete manager
Drinks
- Create a new drink
- Get all drinks
- Get one drink by its ID
- Update one drink
- Delete one drink
Tables
- Create a new table
- Delete a table
- Get all tables
- Select a table
- Unselect a table
Cart
- add drinks to cart
- remove drinks to cart
- get cart
Manager have rights to :
- create, delete, logout managers
- create, update, delete drinks
- create, delete tables
POST /login
Login to have access to restricted endpoints
The request body must contain a JSON object with the following properties:
username
- username of the user/managerpassword
- password of the user/manager
curl -i -X POST -H "Content-Type: application/json" -d
'{
"username":"root",
"password":"1234"
}'http://localhost:8080/login
The response body contains a text object Authentication successful for user: {username}
The response body contains a cookie sessionToken
Set-Cookie: {sessionToken}; Path=/
with sessionToken example value:
Set-Cookie: sessionToken=a2c8b844-23f5-43ac-8a73-a5f5e088f479; Path=/
200
(OK) - login successful400
(Bad Request) - The request body is invalid401
(Unauthorized) - username or password invalid
POST /logout
restricted endpoints, see login
Logout manager
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X POST http://localhost/logout
with sessionToken example value:
curl -i --cookie sessionToken=a2c8b844-23f5-43ac-8a73-a5f5e088f479 -X POST http://localhost/logout
The response body contains a text object : Authentication successful for user: {username}
The response body contains an expired sessionToken
cookie
Set-Cookie: sessionToken=; Path=/; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0
204
(No Content) - logout successful401
(Unauthorized) - invalide sessionToken
POST /managers
restricted endpoints, see login
Create a new manager.
The request body must contain a JSON object with the following properties:
username
- username of the new user/managerpassword
- password of the new user/manager
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X POST -H "Content-Type: application/json" -d
'{
"username":"toto",
"password":"titi"
}' http://localhost:8080/managers
The response body contains a JSON object with the following properties:
username
- username of the new user/managerpassword
- password of the new user/manager
201
(Created) - The drink has been successfully created400
(Bad Request) - The request body is invalid401
(Unauthorized) - invalide sessionToken409
(Conflict) - The username already exists
GET /managers
restricted endpoints, see login
Get all managers username
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} http://localhost:8080/managers
The response body contains a JSON array with the following properties:
username
- username of the user/manager
200
(OK) - request successful401
(Unauthorized) - invalide sessionToken
DELETE /managers/{username}
restricted endpoints, see login
Delete a manager.
/!\ It is not possible to delete your own user /!\
The request path must contain the username
of the manager to delete
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X DELETE http://localhost:8080/managers/toto
The response body is empty.
204
(No Content) - delete successful401
(Unauthorized) - invalide sessionToken401
(Unauthorized) - deleting own user is not allowed404
(Not Found) - The username does not exist
POST /tables
restricted endpoints, see login
Create a new table.
The request body must contain a JSON object with the following properties:
id
- id of the new tableseats
- number of seats of the new table
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X POST -H "Content-Type: application/json" -d
'{
"id":"11",
"seats":"8"
}' http://localhost:8080/tables
The response body contains a JSON object with the following properties:
id
- id of the tableseats
- number of seats of the new tableavailable
- status
201
(Created) - The drink has been successfully created400
(Bad Request) - The request body is invalid401
(Unauthorized) - invalide sessionToken409
(Conflict) - Table id already exists
DELETE /tables/{id}
restricted endpoints, see login
Delete a table with its ID
The request path must contain the id
of the table to delete
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X DELETE http://localhost:8080/tables/11
The response body is empty.
200
(OK) - request successful401
(Unauthorized) - invalide sessionToken404
(Not Found) - table id does not exist
GET /tables
get all tables
The request doesn't contain a parameter.
curl -i -X GET http://localhost:8080/tables
The response body contains a JSON array with the following properties:
id
- id of the tableseats
- number of seats of the new tableavailable
- status
200
(OK) - request successful
GET /setTable/{id}
Select a table to be able to add drinks in cart
The request path must contain the id
of the table to select
curl -i -X GET http://localhost:8080/setTable/10
The response body contains a cookie tableId
Set-Cookie: {tableId}; Path=/
with tableId example value:
Set-Cookie: tableId=11; Path=/
200
(OK) - request successful404
(Not Found) - table id does not exist
GET /clearTable
Clear tableId
cookie
The request doesn't contain a parameter.
curl -i -X GET http://localhost:8080/clearTable
The response body contains an expired tableId
cookie
Set-Cookie: tableId=; Path=/; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0
200
(OK) - request successful
POST /drinks
restricted endpoints, see login
Create a new drinks.
The request body must contain a JSON object with the following properties:
name
- name of the drinkprice
- price of the drink
The request body must contain a valid sessionToken Cookie
curl -i --cookie {sessionToken} -X POST -H "Content-Type: application/json" -d
"{
\"name\":\"Sprite\",
\"price\":\"3.60\"
}"
http://localhost:8080/drinks
The response body contains a JSON object with the following properties:
id
- The unique identifier of the drinkname
- The name of the drinkprice
- The price of the drink
201
(Created) - The drink has been successfully created400
(Bad Request) - The request body is invalid401
(Unauthorized) - invalide sessionToken409
(Conflict) - The drink already exists
GET /drinks
Get all drinks.
The request doesn't contain a parameter.
To get a list of all the drinks you can access/call
http://localhost:8080/drinks
The response body contains a JSON array with the following properties:
id
- The unique identifier of the drinkname
- The name of the drinkprice
- The price of the drink
200
(OK) - Drinks have been successfully retrieved
GET /drinks/{id}
Get one drink by its ID.
The request path must contain the ID of the drink.
To get a drink by its id you can access/call, where {id} is the id of the desired drink
http://localhost:8080/drinks/{id}
The response body contains a JSON object with the following properties:
id
- The unique identifier of the drinkname
- The name of the drinkprice
- The price of the drink
200
(OK) - The drink has been successfully retrieved404
(Not Found) - The drink does not exist
PUT /drinks/{id}
restricted endpoints, see login
Update a drink by its ID.
The request path must contain the ID of the drink.
The request body must contain a JSON object with the following properties:
name
- The name of the drinkprice
- The price of the drink
The request body must contain a valid sessionToken
Cookie
curl -i --cookie {sessionToken} -X PUT -H "Content-Type: application/json" -d
"{
\"name\":\"Coca\",
\"price\":\"3.60\"
}"
http://localhost:8080/drinks/{id}
The response body contains a JSON object with the following properties:
id
- The unique identifier of the drinkname
- The name of the drinkprice
- The price of the drink
200
(OK) - The drink has been successfully updated400
(Bad Request) - The request body is invalid401
(Unauthorized) - invalide sessionToken404
(Not Found) - The drink does not exist
DELETE /drinks/{id}
restricted endpoints, see login
Delete a drink by its ID.
The request path must contain the ID
of the drink.
The request body must contain a valid sessionToken
Cookie
To delete a drink by its id
curl -i --cookie {sessionToken} -X DELETE http://localhost:8080/drinks/{id}
The response body is empty.
204
(No Content) - The drink has been successfully deleted401
(Unauthorized) - invalide sessionToken404
(Not Found) - The drink does not exist
POST /cart
restricted endpoints, see setTable
Add a drink to the cart. If the drink is already in the cart, the current quantity is increased by the quantity defined in the request.
The request body must contain a JSON object with the following properties:
drinkId
- id of the drinkquantity
- quantity of drink ordered
The request body must contain a tableId
Cookie
curl -i --cookie {tableId} -X POST -H "Content-Type: application/json" -d
"{
\"drinkId\":\"2\",
\"quantity\":\"3\"
}"
http://localhost:8080/cart
The response body contains a JSON object with the following properties:
id
- The unique identifier of the drinkname
- The name of the drinkprice
- The price of the drink
204
(No Content) - The drink has been successfully added to cart400
(Bad Request) - The request body is invalid401
(Unauthorized) - invalide tableId404
(Not Found) - The drink does not exist
DELETE /cart/{id}
restricted endpoints, see setTable
Remove a drink from the cart entirely.
The request path must contain the ID
of the drink.
The request body must contain a tableId
Cookie
curl -i --cookie {tableId} -X DELETE http://localhost:8080/cart/{drinkId}
The response body is empty.
204
(No Content) - The drink has been successfully removed from cart401
(Unauthorized) - invalide tableId404
(Not Found) - The drink does not exist
GET /cart
restricted endpoints, see setTable
Get a list of all items in the cart.
The request body must contain a tableId
Cookie
To get a list of all items in cart
curl -i --cookie {tableId} -X GET http://localhost:8080/cart
The response body contains a JSON array with the following properties:
drink
- The drinkid
- Id of the drinkname
- The name of the drinkprice
- The price of the drink
quantity
- The quantity of the drink in the cart
{
"drinks": [
{
"drink": {
"id": 2,
"name": "Rivella",
"price": 2.35
},
"quantity": 3
},
{
"drink": {
"id": 1,
"name": "Coca",
"price": 2.6
},
"quantity": 2
},
{
"drink": {
"id": 3,
"name": "Fanta",
"price": 3.35
},
"quantity": 3
}
]
}
200
(OK) - Drinks have been successfully retrieved401
(Unauthorized) - invalide tableId