Reservation IO API is a little project I have created as a technical evaluation. It consists on a few endpoints which allow you create, read, update and delete Users and their Reservations. If you want to test this project, follow the steps under Installation.
Requirements:
- VirtualBox 64bits
- Vagrant
- Github (Optional)
Steps:
-
Install VirtualBox 64bits and Extension Pack (Recommended).
Reference: https://www.virtualbox.org/wiki/Downloads
-
Install Vagrant.
Reference: https://www.vagrantup.com/downloads.html
-
Download project to your local environment.
Download ZIP:
$ wget https://github.com/darieldejesus/example-php-project/archive/develop.zip
Or you can clone the project locally:
$ git clone [email protected]:darieldejesus/example-php-project.git
-
Go to vagrant directory and start the virtual machine.
$ cd vagrant/ $ vagrant up
After this step, Vagrant would setup the virtual dev environment automatically.
-
After virtual dev environment is setup, login into the machine to confirm it is working. Then, execute some required configurations.
$ cd example-php-project/vagrant/ $ vagrant ssh $ cd /home/www # Required config $ php artisan migrate $ php artisan key:generate
Here you would see all files related to the project.
-
In order to access to the API via a local domain, you need to add this entry in the hosts file:
OSX/Linux
$ sudo su $ echo '192.168.1.123 reservation.io' >> /etc/hosts
-
The latest step is run Unit tests to confirm everything is working as expected:
$ cd example-php-project/vagrant/ $ vagrant ssh $ cd /home/www $ phpunit
Basically the API contains two main entities (User and Reservation) and you can manage them using these endpoints:
URI | Method | Action |
---|---|---|
/api/v1/users | POST | Create a new User |
/api/v1/users/[id] | GET | Return an User by [id] |
/api/v1/users/[id] | PUT | Update an User by [id] |
/api/v1/users/[id] | DELETE | Remove an User by [id] |
/api/v1/users/[id]/reservations | GET | Return all reservations by User [id] |
/api/v1/reservations | POST | Create a new Reservation |
/api/v1/reservations/[id] | DELETE | Remove a Reservation by [id] |
/api/v1/users/recommendations/[id] | GET | Return all users around User by [id] |
Create an User: POST http://reservation.io/api/v1/users
Request body:
{
"email" : "[email protected]",
"name" : "John Doe",
"first_name" : "John",
"last_name" : "Doe Curtis",
"age" : 15,
"host" : false,
"birth_date": "1979-06-09"
}
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": {
"email": "[email protected]",
"name": "John Doe",
"first_name": "John",
"last_name": "Doe Curtis",
"age": 15,
"host": false,
"birth_date": "1979-06-09",
"updated_at": "2016-11-16 22:59:36",
"created_at": "2016-11-16 22:59:36",
"id": 31121
}
}
Return an User by id: GET http://reservation.io/api/v1/users/31121
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": {
"id": 31121,
"first_name": "John",
"last_name": "Doe Curtis",
"age": 15,
"birth_date": "1979-06-09",
"host": 0,
"name": "John Doe",
"email": "[email protected]",
"created_at": "2016-11-16 22:59:36",
"updated_at": "2016-11-16 22:59:36",
"latitude": "",
"longitude": ""
}
}
Update an user property: PUT http://reservation.io/api/v1/users/31121
Request body:
{
"name" : "John Doe",
"first_name" : "John"
}
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": {
"id": 31121,
"first_name": "John",
"last_name": "Doe Curtis",
"age": 15,
"birth_date": "1979-06-09",
"host": 0,
"name": "John Doe",
"email": "[email protected]",
"created_at": "2016-11-16 22:59:36",
"updated_at": "2016-11-16 22:59:36",
"latitude": "",
"longitude": ""
}
}
Remove an User: DELETE http://reservation.io/api/v1/users/31121
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": true
}
Create a new Reservation: POST http://reservation.io/api/v1/reservations
Request body:
{
"host_id": 31122,
"guest_ids": [22117, 22118, 22119]
}
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": true
}
Get the reservations from an User: GET http://reservation.io/api/v1/users/31122/reservations
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": {
"reservations": [
{
"reservation_id": 15,
"host": 31122,
"guest": 22117
},
{
"reservation_id": 16,
"host": 31122,
"guest": 22118
},
{
"reservation_id": 17,
"host": 31122,
"guest": 22119
}
]
}
}
Remove a Reservation: DELETE http://reservation.io/api/v1/reservations/15
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": true
}
Return all Users arround current User by id: GET http://reservation.io/api/v1/users/recommendations/22129
Response body:
{
"code": 200,
"status": "OK",
"message": "success",
"response": {
"user_ids": [
22121,
22125,
...
]
}
}