RESTful API server for Hangman game
-
Clone repo into your path.
-
Setup virtual host to repo/path/api/web and hosts.
For example:
<VirtualHost *:80> ServerName api.hangman.local ServerAdmin webmaster@localhost DocumentRoot /var/www/hangman.local/api/web <Directory /var/www/hangman.local/api/web> AllowOverride All Order allow,deny Allow from all # New directive needed in Apache 2.4.3: Require all granted </Directory> </VirtualHost>
-
Copy config from
application.ini.dist
toapplication.ini
in path/api/Src/Application/Config
and put your settings for DB and service key. -
Run composer:
php composer.phar install
-
Load default words. Run command
curl -X GET http://api.hangman.local/service/loadWords/123456
.123456
- is a service key fromapplication.ini
. -
Application ready for use.
- list all games:
curl -X GET http://api.hangman.local/games
- Create new game:
curl -X POST http://api.hangman.local/games
. This returns game ID in JSON response. - Get game info:
curl -X GET http://api.hangman.local/games/<ID>
. Returns: id, word, tiers_left, status in JSON response - Guess letter:
curl -X POST http://api.hangman.local/games/<ID>?char=<char>
. Returns game info
This simple application developed using FrontController pattern and little similar to MVC pattern. There are implemented Unit tests as well. Also application has routing system, good request and response logic, implemented bootstrap for doing additional actions. Response can use few providers for convert data. By default application are using JsonProvide, but if needed, can be added any provider. Provider based on interface. Request can be changed during application process, for example in bootstrap. Models are implemented with using simple ActiveRecord pattern implementation. For DB used MySQL PDO adapter. There is could be implemented and use another adapter.
In general application are flexible, any developer can add some its own features, adapters, providers, APIObjects and models etc.