vjeantet/silex-simple-rest-swagger

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple silex skeleton for rest api with swagger documentation

Installs: 63

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 97

Language:JavaScript

Type:project

v3.0.1 2014-06-02 20:42 UTC

This package is not auto-updated.

Last update: 2023-01-07 11:47:36 UTC


README

License Latest Stable Version Dependency Status Build Status

A simple silex skeleton application for writing RESTful API. Based on the silex-simple-rest github repo from Alessandro Arnodo. silex-simple-rest-swagger is a fork, which add a swagger REST API Documentation, auto generated.

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.

####How do I run it? From this folder run the following commands to install the php and bower 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 vjeantet/silex-simple-rest-swagger

Your api is now available at http://localhost:9001/api/v1.

You can visualise your api documentation going to : http://localhost:9001/swagger-ui//

####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
POST ->   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"

#POST (update)
curl -X POST 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

License

see LICENSE file.