GithubHelp home page GithubHelp logo

silex-simple-rest's Introduction

Silex Simple REST

Latest Stable Version Total Downloads Build Status

A simple silex skeleton application for writing RESTful API. Developed and maintained by Alessandro Arnodo.

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?

After download the last release, 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 to

GET  ->   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

License

see LICENSE file.

silex-simple-rest's People

Contributors

bryant1410 avatar davydhaeyer avatar fabianfabian avatar itsjw avatar kevich avatar vesparny avatar websoftix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silex-simple-rest's Issues

Add validations to base project

It would be great if you could add some basic validations to the base project.

I'm new on sylex (indeed, I started after seeing this base project) and I'm not sure where I should include validation, if in the controller, service, or elsewhere

Thanks

Pagination?

I think it would be nice to incorporate patterns for pagination. It is a must on every API.

Move the database from the root folder to the storage folder

Everything about this code seems perfect, except that the app.db is located in the root folder of the project. I was wondering if it's more appropriate and cleaner to put it in the storage folder instead, i.e. /storage/app.db. It's only one path change in app.php, where DoctrineServiceProvider() is registered.

Authentication and further Testing

How would you handle REST Authentication on your app?

And would you create a test for each service? What about end to end Testing?

Great work you have there.
Thank you

Remove references to angular project

You should remove angular js references in project (like in .htaccess or phpunit XML) and replace them for some placeholders, and remember the public to replace them in the readme.md

Thanks

Need to handle request parameters

how handle request parameters ?

One solution is to register SessionServiceProvider
$app->register(new Silex\Provider\SessionServiceProvider());

Add fixtures for testing

It would be great if you could include in the project some kind of fixture load mechanism for test cases purpose..

Thanks

Show stack trace only in debug mode.

Its stongly recommended do not show stack trace to the everyone API user. You should show this info only if debug mode is enabled, otherwise don't show it.

For example:

    $data = [
        'statusCode' => $code,
        'message' => $e->getMessage(),
    ];

    if ($app['debug']) {
        $data['stacktrace'] = $e->getTraceAsString();
    }

    return new JsonResponse($data);

after method

How to implement after method with particular routes
Ex. $api->post('/notes', "notes.controller:save"); //src/App/RoutesLoader.php

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.