Skip to content

Instantly share code, notes, and snippets.

@dingram
Created February 28, 2010 02:06
Show Gist options
  • Save dingram/317117 to your computer and use it in GitHub Desktop.
Save dingram/317117 to your computer and use it in GitHub Desktop.
<?php
function echoRequest(ReqtRequest $request) {
$resp = new RestResponseOk(array(
'url' => $url,
'verb' => $verb,
'headers' => $headers,
'args' => $get_args,
'body' => $body,
), $request);
$resp->render();
return true;
}
function echoRequest2(RestRequest $request) {
$resp = new RestResponseOk(array(
'echoRequest' => array(
'url' => $url,
'verb' => $verb,
'headers' => $headers,
'args' => $get_args,
'body' => $body,
'matches' => $matches,
)
), $request);
$resp->render();
return true;
}
function wink(RestRequest $request) {
$resp = new RestResponseOk(array(
'wink' => ';)',
), $request);
$resp->render();
return true;
}
RestRequest::setBasePath('/rest-test');
// handle GET requests to root with the echoRequest function
RestRequest::registerHandler('/', 'echoRequest');
// handle GET and POST to /echo or anything under it with echoRequest2
RestRequest::registerPatternHandler('^/echo(/.*)?$', 'echoRequest2', array('GET', 'POST'));
// easter egg for anyone using the non-standard WINK verb
RestRequest::registerPatternHandler('^/', 'wink', array('WINK'));
RestRequest::dispatchFromCurrent();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment