kanellov / myRestApi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The API consists of the following methods:

Method  URL                                     Action
GET     /api/v1/creatures/                      Retrieves all creatures
GET     /api/v1/creatures/?creature_type=ninja  Retrieves all creatures based on type
GET     /api/v1/creatures/2                     Retrieves creature based on primary key
POST    /api/v1/creatures/                      Adds a new creature
DELETE  /api/v1/creatures/2                     Deletes creature based on primary key
PUT     /api/v1/creatures/2                     Updates creature based on primary key
PUT     /api/v1/creatures/2/hitWithAxe          Performs action based on primary key
PUT     /api/v1/creatures/2/performMagicSpell   Performs action based on primary key
PUT     /api/v1/creatures/2/drinkHealingPotion  Performs action based on primary key

===============================================================================================
EXAMPLES OF USE

Fill the database with some creatures:

curl -X POST -d {"name" : "Blade" , "health" : 10000, "creature_type" : "vampire"} http://localhost/sociomantic/api/v1/creatures/
curl -X POST -d {"name" : "random zombie 1" , "health" : 2500, "creature_type" : "zombie"} http://localhost/sociomantic/api/v1/creatures/
curl -X POST -d {"name" : "random zombie 2" , "health" : 2500, "creature_type" : "zombie"} http://localhost/sociomantic/api/v1/creatures/
curl -X POST -d {"name" : "Kung Fu Panda" , "health" : 5000, "creature_type" : "ninja"} http://localhost/sociomantic/api/v1/creatures/
curl -X POST -d {"name" : "Barbarossa" , "health" : 7500, "creature_type" : "pirate"} http://localhost/sociomantic/api/v1/creatures/

Retrieve all creatures:

curl -X GET http://localhost/sociomantic/api/v1/creatures/

Retrieve all ninja:

curl -X GET http://localhost/sociomantic/api/v1/creatures/?creature_type=ninja

Retrieve specific creature ("Kung Fu Panda"):

curl -X GET http://localhost/sociomantic/api/v1/creatures/4

Update creature (send "Kung Fu Panda" to the navy..):

curl -X PUT -d {"creature_type" : "pirate"} http://localhost/sociomantic/api/v1/creatures/3 

Delete creature (never liked zombies, so kill "random zombie 2"):

curl -X DELETE http://localhost/sociomantic/api/v1/creatures/3 

Perform action (hit "random zombie 1"):

curl -X PUT http://localhost/sociomantic/api/v1/creatures/3/hitWithAxe

Perform action (hit "random zombie 1" again!):

curl -X PUT http://localhost/sociomantic/api/v1/creatures/3/performMagicSpell

About


Languages

Language:PHP 98.2%Language:ApacheConf 1.8%