dev-master
9999999-devA silex skeleton for rest api
MIT
The Requires
The Development Requires
by SiteOffice
by Alessandro Arnodo
api framework rest silex
A silex skeleton for rest api
A simple skeleton application for writing RESTful API., (*1)
After cloning project, from the root folder of the project, run the following command to install the php dependencies., (*2)
composer install
Set your database then copy resources/config/prod.php to resouces/config/config.php, update with your database params then run., (*3)
php bin/routesGenerator.php
In production environment, authentification key is required, to generate it run the following command., (*4)
php bin/keyGenerator.php all
Your api is now available at http://localhost/api/v1., (*5)
Some tests were written, and all CRUD operations are fully tested :), (*6)
From the root folder run the following command to run tests., (*7)
vendor/bin/phpunit
The api will respond to, (*8)
GET -> http://localhost/api/v1/myTable GET -> http://localhost/api/v1/myTable/{id} POST -> http://localhost/api/v1/myTable/search POST -> http://localhost/api/v1/myTable PUT -> http://localhost/api/v1/myTable/{id} DELETE -> http://localhost/api/v1/myTable/{id}
Your request should have 'Content-Type: application/json' and 'key: myKey' headers. Your api is CORS compliant out of the box, so it's capable of cross-domain communication., (*9)
Try with curl:, (*10)
#GET curl http://localhost/api/v1/myTable -H 'Content-Type: application/json' -H 'key: myKey' -w "\n" curl http://localhost/api/v1/myTable/1 -H 'Content-Type: application/json' -H 'key: myKey' -w "\n" #POST (search) curl -X POST http://localhost/api/v1/myTable/search -d '{"note":"Hello World!"}' -H 'Content-Type: application/json' -H 'key: myKey' -w "\n" #POST (insert) curl -X POST http://localhost/api/v1/myTable -d '{"note":"Hello World!"}' -H 'Content-Type: application/json' -H 'key: myKey' -w "\n" #PUT (update) curl -X PUT http://localhost/api/v1/myTable/1 -d '{"note":"Uhauuuuuuu!"}' -H 'Content-Type: application/json' -H 'key: myKey' -w "\n" #DELETE curl -X DELETE http://localhost/api/v1/myTable/1 -H 'Content-Type: application/json' -H 'key: myKey' -w "\n"
Under the resources folder you can find a .htaccess file to put the api in production., (*11)
A silex skeleton for rest api
MIT
api framework rest silex