Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created January 5, 2017 19:44
Show Gist options
  • Select an option

  • Save thejhh/cd4ac0813e71237bcc23c200ab2119ba to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/cd4ac0813e71237bcc23c200ab2119ba to your computer and use it in GitHub Desktop.
Sample PHP REST Service
<?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);
}
}
<?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');
}
}
<?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