2017 © Pedro Peláez
 

library silex-rest

A silex skeleton for rest api

image

siteoffice/silex-rest

A silex skeleton for rest api

  • Thursday, August 11, 2016
  • by sdugene
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 104 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Silex REST

A simple skeleton application for writing RESTful API., (*1)

How do I run it?

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)

Run tests

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 

What you will get

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)

The Versions

11/08 2016

dev-master

9999999-dev

A silex skeleton for rest api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Arnodo

api framework rest silex