Album application with API fisrt approach
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
data/cache
module
provision
public
.gitignore
LICENSE.txt
README.md
Vagrantfile
composer.json
composer.phar
init_autoloader.php

README.md

zfAlbum

Introduction

This is a simple Album application presented in Rob Allen's and Jason Grimes's tutorials. However, all backend calls are done through API server by using backbone on front end

Application deploys Doctrine 2 and phly/phly-restfully module on backend.

The following standards used for RESTful JSON APIs:

  • HAL, used for creating hypermedia links
  • Problem API, used for reporting API problems
  • CORS, used for "cross-domain" requests

Prerequisite

  • MySQL
  • PHP 5.4

Installation

git clone https://github.com/denisura/zfAlbum.git tmp
cd tmp&&php composer.phar install --dev

Configuration

Set DB connection params in config/autoload/doctrine.local.php

Default values are:

host     : localhost
port     : 3306
user     : root
password :
dbname   : zfalbum

Schema deployment

Doctrine Schema validation

./vendor/bin/doctrine-module.bat orm:validate-schema

Doctrine Schema creation

 ./vendor/bin/doctrine-module.bat orm:schema-tool:create

Development

Start standalone server shipped with PHP 5.4

  1. Run API server on port 8080:
php -S localhost:8080 -t app
  1. Run web server:
php -S localhost -t public

Web Access on http://localhost

UnitTests

Album UnitTests:

vendor/bin/phpunit.bat --configuration module/Album/test/

Application UnitTests:

vendor/bin/phpunit.bat --configuration module/Application/test/

API Usage

Add new album

curl -X POST --data "title=Yesterday&artist=beatles"  --header "Accept:application/json" http://localhost:8080/v1/albums

Response:

{
   "id":27,
   "artist":"beatles",
   "title":"Yesterday",
   "_links":{
      "self":{
         "href":"http:\/\/localhost:8080\/v1\/albums\/27"
      }
   }
}

Replace existing album

curl -X PUT --data "title=Help&artist=beatles"  --header "Accept:application/json" http://localhost:8080/v1/albums/27

Response:

{
   "id":27,
   "artist":"beatles",
   "title":"Help",
   "_links":{
      "self":{
         "href":"http:\/\/localhost:8080\/v1\/albums\/27"
      }
   }
}

Update only some property of existing album

curl -X PATCH --data "title=Girl"  --header "Accept:application/json" http://localhost:8080/v1/albums/27

Response:

{
   "id":27,
   "artist":"beatles",
   "title":"Girl",
   "_links":{
      "self":{
         "href":"http:\/\/localhost:8080\/v1\/albums\/27"
      }
   }
}

Delete album

curl -X DELETE --header "Accept:application/json" http://localhost:8080/v1/albums/5

Delete all albums

curl -X DELETE --header "Accept:application/json" "http://localhost:8080/v1/albums"