https://github.com/vikbert/rest-selektion-silex
a simple rest api selekton with silex framework
https://github.com/vikbert/rest-selektion-silex
Last synced: 11 months ago
JSON representation
a simple rest api selekton with silex framework
- Host: GitHub
- URL: https://github.com/vikbert/rest-selektion-silex
- Owner: vikbert
- License: mit
- Created: 2015-11-18T20:48:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-18T20:48:37.000Z (over 10 years ago)
- Last Synced: 2025-06-24T20:49:11.831Z (12 months ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Silex Simple REST Selekton
=============================
A simple silex skeleton application for writing RESTful API.
**This project wants to be a starting point to writing scalable and maintainable REST api with Silex PHP micro-framework**
####How do I run it?
After download the last version, from the root folder of the project, run the following commands to install the php dependencies, import some data, and run a local php server.
You need at least php **5.4.*** with **SQLite extension** enabled and **Composer**
composer install
sqlite3 app.db < resources/sql/schema.sql
php -S 0:9001 -t web/
You can install the project also as a composer project
composer create-project vesparny/silex-simple-rest
Your api is now available at http://localhost:9001/api/v1.
####Run tests
Some tests were written, and all CRUD operations are fully tested :)
From the root folder run the following command to run tests.
vendor/bin/phpunit
####What you will get
The api will respond to
GET -> http://localhost:9001/api/v1/notes
POST -> http://localhost:9001/api/v1/notes
PUT -> http://localhost:9001/api/v1/notes/{id}
DELETE -> http://localhost:9001/api/v1/notes/{id}
Your request should have 'Content-Type: application/json' header.
Your api is CORS compliant out of the box, so it's capable of cross-domain communication.
Try with curl:
#GET
curl http://localhost:9001/api/v1/notes -H 'Content-Type: application/json' -w "\n"
#POST (insert)
curl -X POST http://localhost:9001/api/v1/notes -d '{"note":"Hello World!"}' -H 'Content-Type: application/json' -w "\n"
#PUT (update)
curl -X PUT http://localhost:9001/api/v1/notes/1 -d '{"note":"Uhauuuuuuu!"}' -H 'Content-Type: application/json' -w "\n"
#DELETE
curl -X DELETE http://localhost:9001/api/v1/notes/1 -H 'Content-Type: application/json' -w "\n"
####What's under the hood
Take a look at the source code, it's self explanatory :)
More documentation and info about the code will be available soon.
Under the resources folder you can find a .htaccess file to put the api in production.
see LICENSE file.