Пример #1
0
function get_url_id()
{
    $strip = basename($_SERVER['REQUEST_URI']);
    $strip = explode("?", $strip);
    if (count($strip) > 0) {
        return $strip[0];
    }
    return NULL;
}
switch ($request_method) {
    case 'get':
        $result = $query->getRichiesta(new stdClass());
        break;
    case 'put':
        $put = file_get_contents("php://input", 'r');
        $params = json_decode($put);
        $result = $query->updateRichiesta($params);
        break;
    case 'post':
        $put = file_get_contents("php://input", 'r');
        $params = json_decode($put);
        $result = $query->createRichiesta($params);
        break;
    case 'delete':
        $id = get_url_id();
        $params = new stdClass();
        $params->id = $id;
        $result = $query->destroyRichiesta($params);
        break;
}
echo json_encode($result);