This project tries to be a native implementation of an API in PHP. It's decoupled from any framework and only uses PHP-DI as a dependency container.
- Install Docker
- Install Composer
- Clone this project:
git clone https://github.com/adrianRoldan/api-without-frameworks.git api-users-php
- Move to the project folder:
cd api-users-php
- Run:
cp config/database.example.php config/database.php
- Configure database.php file with:
"host" => "database"
"user" => "api"
"pass" => "api"
"database" => "api-users"
"port" => 3306
- Run:
composer install
- Execute
docker-compose build
- Execute
docker-compose up -d
The application runs in the port 3000: http://localhost:3000/
The postman collection.json file has the collection of API requests available with the input data to import into postman.
POST
/user/create/
Input parameters:
{
"name" : "name",
"lastName" : "lastName",
"phone" : "phone"
}
GET
/user/contacts
Input parameters:
userId=userId
POST
/user/contacts/create
Input parameters:
{
"userId": 2,
"contacts": [
...
{
"contactName": "Paco",
"phone": 639916718
},
{
"contactName": "Adela",
"phone": 634716718
},
{
"contactName": "Angel",
"phone": 639916712
}
...
]
}
PUT
/user/contacts/update
Input parameters:
{
"userId": 1,
"contacts": [
{
"contactName": "Martin",
"phone": 939916718
},
{
"contactName": "Guillermo",
"phone": 934512114
}
]
}
GET
/user/contacts/common
Input parameters:
userId1=userId1
userId2=userId2
- Execute PHPUnit tests:
docker exec api-users-apache-php ./vendor/bin/phpunit
This is a simple users API. Users can have none or many contacts in their address book.