echo json_encode("ERROR!"); } $method = $_SERVER['REQUEST_METHOD']; $request = $_SERVER['REQUEST_URI']; switch ($method) { case 'PUT': parse_str(file_get_contents('php://input'), $put_vars); sendHeaders(); $data = $put_vars; rest_put($request, $data); break; case 'POST': sendHeaders(); $data = $_POST; rest_post($request, $data); break; case 'GET': sendHeaders(); $data = $_GET; rest_get($request, $data); break; case 'DELETE': sendHeaders(); rest_delete($request); break; default: header("{$_SERVER['SERVER_PROTOCOL']} 404 Not Found"); rest_error($request); break; } exit;
<?php $method = $_SERVER['REQUEST_METHOD']; $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1)); include "db.php"; switch ($method) { case 'PUT': rest_put($request, $dblink); break; case 'POST': rest_post($request, $dblink); break; case 'GET': rest_get($request, $dblink); break; case 'DELETE': rest_delete($request); break; default: rest_error($request); break; } function rest_put($req, $dblink) { $jsonText = file_get_contents('php://input'); $idDash = generateRandomString(); $query = "insert into stat (json, id_dash) values (?, ?)"; $stmt = $dblink->prepare($query) or die("Prepare stmt die."); $stmt->bind_param("ss", $jsonText, $idDash); $stmt->execute(); echo '{ "id":"' . $idDash . '"}';
} // Route based on what type of request this is. $method = $_SERVER['REQUEST_METHOD']; switch ($method) { case 'DELETE': rest_delete(); break; case 'POST': rest_post(); break; case 'PUT': rest_put(); break; case 'GET': default: rest_get(); break; } /* Handle GET requests */ function rest_get() { global $projectid; $subprojectid = get_subprojectid(); if ($subprojectid === false) { return; } $start = microtime_float(); $response = begin_JSON_response(); $response['projectid'] = $projectid; $response['subprojectid'] = $subprojectid; $SubProject = new SubProject();
function broadecos_ws_type_lrs_statement_get($resource, $context, $params, $pathParams) { $url = 'http://' . getLRSUrl() . '/data/xAPI/statements?' . $_SERVER['QUERY_STRING']; $headers = array(); $headers[] = 'Content-Type: application/json'; $headers[] = 'X-Experience-API-Version: 1.0.0'; $headers[] = 'Authorization: Basic ' . getLRSAuthorizationHash(); $response = rest_get($url, $headers); return json_decode($response, true); }
$value = rest_put($put_vars['id'], $put_vars['like']); exit(json_encode($value)); }); $app->get('/comment/:post_id', function ($post_id) { include 'comment.php'; $value = rest_get($post_id); exit(json_encode($value)); }); $app->post('/comment', function () use($app) { include 'comment.php'; $value = rest_post(); exit(json_encode($value)); }); $app->get('/profile/:user_id', function ($user_id) { include 'profile.php'; $value = rest_get($user_id); exit(json_encode($value)); }); $app->post('/profile', function () use($app) { include 'profile.php'; $put_vars = $app->request->post(); $keys = array_keys($put_vars); $values = array_values($put_vars); $value = rest_post($keys, $values); exit(json_encode($value)); }); $app->put('/profile/:id', function ($id) use($app) { include 'profile.php'; $put_vars = $app->request->put(); $keys = array_keys($put_vars); $values = array_values($put_vars);
return $result; } function rest_get($table, $id = null) { $ch = get_curl($table, $id); return execute_curl($ch); } function rest_post($table, $values) { $ch = get_curl($table, null); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, implode('|', $values)); return execute_curl($ch); } function rest_delete($table, $id) { $ch = get_curl($table, $id); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); return execute_curl($ch); } echo "Getting students:\n"; echo rest_get('students'); echo "Adding a new student:\n"; $response = rest_post('students', array('Vardenis', 'Pavardenis', '857471588')); preg_match('/Row id: ([0-9]+)/', $response, $matches); $id = $matches[1]; echo $response; echo "Getting students:\n"; echo rest_get('students'); echo "Deleting student:\n"; echo rest_delete('students', $id);
function view_recent($count) { $response = rest_get(API_BASE_URL . "viewLastActivity.count=" . $count . ".token=" . DEVICE_CODE); return $response; }
$db = new DatabaseConnection($dbparams); $table = $request[0]; if (isset($request[1])) { $id = $request[1]; } else { $id = null; } switch ($method) { case 'PUT': rest_put($table, $id, $db); break; case 'POST': rest_post($table, $id, $db); break; case 'GET': rest_get($table, $id, $db, $params); break; case 'HEAD': rest_head($table, $id, $db); break; case 'DELETE': rest_delete($table, $id, $db); break; case 'OPTIONS': rest_options($table, $id, $db); break; default: rest_error(); break; } }