A simple API REST for users administration
Run the composer to install laravel and dependencies
$ composer install
To generate your key
$ php artisan key:generate
And then run the migrations to create the database tables along with the seeds to populate the tables
$ php artisan migrate --seed
There is even a docker-compose file. You must have docker and docker-compose installed. And then run the command:
$ docker-compose up -d
If you want to use docker, configure the .env file according to docker-compose
or copy the .env-docker.example
file and rename to .env
.
Return a json list of all users registered
-
URL
/users
-
Method
GET
-
Header
Content-Type: application/x-www-form-urlencoded
-
Data
None
-
Success Response
- Code:
200
Content:[{"id":1,"name":"John Doe","age":61,"email":"[email protected]","phone":"(99) 99999-9999","city":"City Name","state":"AA","created_at":"YYYY-MM-DD HH:MM:SS","updated_at":"YYYY-MM-DD HH:MM:SS"}]
- Code:
-
Error Response
- Code:
200
Content:{"response":"No registered users"}
- Code:
Return json about a single user
-
URL
/users/{id}
-
Method
GET
-
Header
Content-Type: application/x-www-form-urlencoded
-
Data
None
-
Success Response
- Code:
200
Content:[{"id":1,"name":"John Doe","age":61,"email":"[email protected]","phone":"(99) 99999-9999","city":"Porto Guilherme","state":"CE","created_at":"2019-06-16 02:47:53","updated_at":"2019-06-16 02:47:53"}]
- Code:
-
Error Response
- Code:
404
Content:{"error":"User not found"}
- Code:
-
URL
/users
-
Method
POST
-
Header
Content-Type: application/x-www-form-urlencoded
-
Data
name
string
ageint
emailstring
phonestring
citystring
statestring
-
Success Response
- Code:
201
Content:{"response": "User {name} created"}
- Code:
-
Error Response
- Code:
400
Content:{"error": ...}
- Code:
-
URL
/users/{id}
-
Method
PUT
-
Header
Content-Type: application/x-www-form-urlencoded
-
Data
name
string
ageint
emailstring
phonestring
citystring
statestring
-
Success Response
- Code:
201
Content:{"response": "User {name} updated"}
- Code:
-
Error Response
- Code:
400
Content:{"error": ...}
- Code:
-
URL
/users/{id}
-
Method
DELETE
-
Header
Content-Type: application/x-www-form-urlencoded
-
Data
None
-
Success Response
- Code:
201
Content:{"response": "User deleted"}
- Code:
-
Error Response
- Code:
404
Content:{"error": "User not found"}
- Code:
To run tests if you're using docker, you need to start the command line using docker-compose exec web
followed by comando you need, eg.:
$ docker-compose exec web vendor/bin/phpunit
If you don't, to run the 2 tests written run this command:
$ vendor/bin/phpunit