Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vesparny/silex-simple-rest
A simple silex skeleton for writing scalable rest api
https://github.com/vesparny/silex-simple-rest
Last synced: about 2 months ago
JSON representation
A simple silex skeleton for writing scalable rest api
- Host: GitHub
- URL: https://github.com/vesparny/silex-simple-rest
- Owner: vesparny
- License: mit
- Created: 2012-09-03T21:36:34.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2018-01-21T13:13:09.000Z (over 6 years ago)
- Last Synced: 2024-07-01T02:01:55.105Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 65.4 KB
- Stars: 337
- Watchers: 34
- Forks: 96
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Silex Simple REST
[![Latest Stable Version](https://poser.pugx.org/vesparny/silex-simple-rest/v/stable.png)](https://packagist.org/packages/vesparny/silex-simple-rest) [![Total Downloads](https://poser.pugx.org/vesparny/silex-simple-rest/downloads.png)](https://packagist.org/packages/vesparny/silex-simple-rest) [![Build Status](https://secure.travis-ci.org/vesparny/silex-simple-rest.png)](http://travis-ci.org/vesparny/silex-simple-rest)
A simple silex skeleton application for writing RESTful API. Developed and maintained by [Alessandro Arnodo](http://alessandro.arnodo.net).
**This project wants to be a starting point to writing scalable and maintainable REST api with Silex PHP micro-framework**
Continuous Integration is provided by [Travis-CI](http://travis-ci.org/).
#### How do I run it?
After download the last [release](https://github.com/vesparny/silex-simple-rest/releases), 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.5.9*** 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 toGET -> http://localhost:9001/api/v1/notes
GET -> http://localhost:9001/api/v1/notes/{id}
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 (collection)
curl http://localhost:9001/api/v1/notes -H 'Content-Type: application/json' -w "\n"
#GET (single item with id 1)
curl http://localhost:9001/api/v1/notes/1 -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.
#### Contributing
Fell free to contribute, fork, pull request, hack. Thanks!
#### Author
+ [@vesparny](https://twitter.com/vesparny)
+ [http://alessandro.arnodo.net](http://alessandro.arnodo.net)
+
## License
see LICENSE file.