Created
January 5, 2017 19:44
-
-
Save thejhh/cd4ac0813e71237bcc23c200ab2119ba to your computer and use it in GitHub Desktop.
Sample PHP REST Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Security check */ | |
| if (!defined('SendanorERP')) { | |
| die("Direct access not permitted\n"); | |
| } | |
| /** Client collection */ | |
| class ClientCollection extends DatabaseCollection { | |
| /** */ | |
| public function __construct() { | |
| parent::__construct(); | |
| parent::setTable('client'); | |
| } | |
| /** Get all Client objects */ | |
| public function get (iRequest $request) { | |
| $query = $request->getQuery(); | |
| if (!isset($query['email'])) { | |
| throw new HTTPError(400, "email-required"); | |
| } | |
| return parent::get($request); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Security check */ | |
| if (!defined('SendanorERP')) { | |
| die("Direct access not permitted\n"); | |
| } | |
| /** Client Element */ | |
| class ClientElement extends DatabaseElement { | |
| /** */ | |
| public function __construct() { | |
| parent::__construct(); | |
| parent::setTable('client'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('SendanorERP', TRUE); | |
| require('../etc/config.php'); | |
| require('../lib/index.php'); | |
| REST::run(array( | |
| "/client" => "ClientCollection", | |
| "/client/:id" => "ClientElement" | |
| )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment