This is the simple REST Api implementing basic CRUD operations related to a user.
To get the latest source you can use git clone.
$ git clone https://github.com/ghazanfarmir/Slim-RestApi-CRUD.git /path/to/slim-rest-api-crud
Installation can be done with the use of composer. If you don't have composer yet you can install it by doing:
$ curl -s https://getcomposer.org/installer | php
To install it globally
$ sudo mv composer.phar /usr/local/bin/composer
$ cd /path/to/slim-rest-api-crud
$ composer update
$ composer install
- Import
dababase/mysql.sql
in your MySQL Server, this will createusers
table. - Copy
.env.example
to.env
- Update .env with your database credentials
// .env
# Database
DB_DRIVER=mysql
DB_HOST=localhost
DB_NAME=
DB_USERNAME=
DB_PASSWORD=
$ GET /api/v1/users // all users
$ GET /api/v1/users/{id} // specific user
$ POST /api/v1/users // add new user
$ PUT /api/v1/users/{id} // update an existing user
$ DELETE /api/v1/users/{id} // delete an existing user
{
"first_name": "John",
"surname": "Doe",
"email": "johndoe@example.com",
"date_of_birth": "1920-03-02"
}
{
"first_name": "John",
"surname": "Doe",
"email": "johndoe@example.com",
"date_of_birth": "1920-03-02"
}
...
Each endpoint provides an JSON response with relevant data
{
'code': 200,
'total_results': {total_items_count}
'data': [
{ ... },
{ ... },
{ ... },
...
]
}
{
'code': 200,
'data': {
...
...
}
}
OR
{
'code': 404,
'message': 'no user found'
}
{
'code': 201,
'message': 'New user added successfully.',
'data': {
...
...
}
}
{
'code': 200,
'message': 'User has been updated successfully.',
'data': {
...
...
}
}
{
'code': 200,
'message': 'User has been deleted successfully.'
}