// Refer: http://jaxl.readthedocs.org/en/latest/users/http_extensions.html#dispatch-rules function create_event($request) { JAXLLogger::info("got event create request"); $request->close(); } function read_event($request, $pk) { JAXLLogger::info("got event read request for {$pk}"); $request->close(); } function update_event($request, $pk) { JAXLLogger::info("got event update request for {$pk}"); $request->close(); } function delete_event($request, $pk) { JAXLLogger::info("got event delete request for {$pk}"); $request->close(); } $event_create = array('create_event', '^/event/create/$', array('PUT')); $event_read = array('read_event', '^/event/(?P<pk>\\d+)/$', array('GET', 'HEAD')); $event_update = array('update_event', '^/event/(?P<pk>\\d+)/$', array('POST')); $event_delete = array('delete_event', '^/event/(?P<pk>\\d+)/$', array('DELETE')); // prepare rule set $rules = array($index, $upload, $event_create, $event_read, $event_update, $event_delete); $http->dispatch($rules); // start http server $http->start();
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ // include and configure logger require_once 'jaxl.php'; JAXLLogger::$level = JAXL_INFO; // print usage notice and parse addr/port parameters if passed _colorize("Usage: {$argv['0']} port (default: 9699)", JAXL_NOTICE); $port = $argc == 2 ? $argv[1] : 9699; // initialize http server require_once JAXL_CWD . '/http/http_server.php'; $http = new HTTPServer($port); // catch all incoming requests here function on_request($request) { $body = json_encode($request); $request->ok($body, array('Content-Type' => 'application/json')); } // start http server $http->start('on_request');