https://github.com/maxpou/symfony-rest-beer-edition
:beers: A Symfony application with a REST API
https://github.com/maxpou/symfony-rest-beer-edition
beer hateoas php rest symfony
Last synced: 6 months ago
JSON representation
:beers: A Symfony application with a REST API
- Host: GitHub
- URL: https://github.com/maxpou/symfony-rest-beer-edition
- Owner: maxpou
- License: mit
- Created: 2016-01-22T16:29:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-03T18:55:12.000Z (about 9 years ago)
- Last Synced: 2025-03-27T02:38:29.867Z (6 months ago)
- Topics: beer, hateoas, php, rest, symfony
- Language: PHP
- Homepage:
- Size: 131 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Symfony Rest Beer Edition (Work in progress)
============================================[](https://insight.sensiolabs.com/projects/665c060e-aa8a-458a-b74c-44c5725c7155)
[](https://travis-ci.org/maxpou/symfony-rest-beer-edition)
[](https://scrutinizer-ci.com/g/maxpou/symfony-rest-beer-edition/?branch=master)
[](https://coveralls.io/github/maxpou/symfony-rest-beer-edition?branch=master)
[](https://php.net/)Welcome to the Symfony Rest Beer Edition!
Features in this application:
* Specific HTTP Status Codes (204, 206, 400, 404...), HTTP Verbs (GET/POST/PUT/DELETE/OPTIONS)
* Routes with subresources, collection filters...
* Fully swagger documentation (visit /api/doc)
* Symfony's Form component support
* Routes pluralization (beer -> beers & brewery -> breweries).
*See class ApiBundle\Util\Inflector\BreweryInflector.*
* Serialization exclusion strategies
* HATEOAS with exclusions policies - use [Hypertext Application Language](http://stateless.co/hal_specification.html) (HAL)
* Support JSON/XML format## Installation
1. Update parameters.yml (create a new secret key)
2. Execute this commands```
composer install
php app/console doctrine:database:create
php app/console doctrine:schema:create
php app/console doctrine:fixtures:load -n
```
3. Check configuration by executing `php app/check.php`
4. Test `composer test`## What's inside?
* All Symfony default bundles (FrameworkBundle, DoctrineBundle, TwigBundle, MonologBundle...)
* [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle) - Easily serialize, and deserialize data of any complexity (supports XML, JSON, YAML)
* [FOSRestBundle](https://github.com/FriendsOfSymfony/FOSRestBundle) provides several tools to assist in building REST applications
* [BazingaHateoasBundle](https://github.com/willdurand/BazingaHateoasBundle) provide HATEOAS
* [NelmioApiDocBundle](https://github.com/nelmio/NelmioApiDocBundle) provide a nice documentation for API (inspired by Swagger UI project)
* [NelmioCorsBundle](https://github.com/nelmio/NelmioCorsBundle) adds CORS headers support in your Symfony2 application
* [DoctrineFixturesBundle](DoctrineFixturesBundle) provide breweries and beers (see Maxpou\BeerBundle\DataFixtures\ORM\LoadBeersData.php)And in /src :
* **ApiBundle** : contain API controllers
* **MaxpouBeerBundle** : contains entities, forms, fixtures and back office controllers
* **AppBundle** : Back office controllers... not very important!*Back-office views use [Bootstrap](http://getbootstrap.com) (CDN Host)*
## Focuses
**Entities:**
We have only 2 entities: Brewery and Beer (Many-To-One relationship).**Code First approach:**
I use Code First approach (by opposition to Database/Model First). It's mean that I start by writing classes not model/SQL DDL orders. Otherwise it's hard to maintain (I know, doctrine is reverse engineering compliant).**UUID:**
Prefer UUID instead of auto increment because, it's make harder to discover existing resources (for malignant users). Also, it's might not be unique in distributed systems.## TODO
**REST misconfiguration:**
- [ ] POST /whatever-collection... -> must return HTTP header: `Location: http://app.com/breweries/newidcreated`
- [ ] GET /whatever on array objects, Only put URI
- [ ] GET /whatever-collection -> must return HTTP code 206 (Partial content) and add links into Link HTTP headers (e.g. fist, prev, next and last page)**Enhancements:**
- [ ] Make controllers **more thins!** (use ParamConverter, avoid doctrine researches in controllers)
- [ ] Implement PATCH HTTP method
- [ ] Exclusion strategy: allow HTTP header Prefer/Vary (Request) and Vary/Preference-Applied (Response). Because clients don't need the same information
- [ ] Allow sort collection
- [ ] Add a /serve API to implement HTTP Rate limitation.
HTTP Headers:
* X-RateLimit-Limit: Total number of beer allow to drink ;)
* X-RateLimit-Remaining: Beer left
* X-RateLimit-Reset: remaining window before rate limit resets (UTC epoch seconds)