Example #1
0
    fclose($fp);
    echo "Posted \n";
    echo $data;
});
//  END POST
$app->get('/get', function () {
    $mydata = file_get_contents("test.json");
    print $mydata;
});
// PUT route
$app->put('/put', function () {
    echo 'This is a PUT route';
});
// PATCH route
$app->patch('/patch', function () {
    echo 'This is a PATCH route';
});
// DELETE route
$app->delete('/delete', function () {
    echo 'This is a DELETE route';
});
/*  My APIs */
$app->get('/hello/:name', function ($name) {
    echo "Hello, " . $name;
});
$app->get('/fslist/:foldername', function ($foldername) {
    $targetpath = "../{$foldername}";
    $testexists = file_exists($targetpath);
    $rootdir = preg_replace('~(\\w)$~', '$1' . DIRECTORY_SEPARATOR, realpath($targetpath)) . "*";
    /*
    foreach(glob($rootdir, GLOB_ONLYDIR) as $dir)  
 /**
  * Test PATCH route
  */
 public function testPatchRoute()
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'PATCH', 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar'));
     $s = new \Slim\Slim();
     $mw1 = function () {
         echo "foo";
     };
     $mw2 = function () {
         echo "bar";
     };
     $callable = function () {
         echo "xyz";
     };
     $route = $s->patch('/bar', $mw1, $mw2, $callable);
     $s->call();
     $this->assertEquals('foobarxyz', $s->response()->body());
     $this->assertEquals('/bar', $route->getPattern());
     $this->assertSame($callable, $route->getCallable());
 }
Example #3
0
require 'lib/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
require_once 'includes/api_functions.inc.php';
$app->setName('api');
$app->group('/api', function () use($app) {
    $app->group('/v0', function () use($app) {
        $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');
        // api/v0/bgp
        $app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized');
        $app->group('/devices', function () use($app) {
            $app->delete('/:hostname', 'authToken', 'del_device')->name('del_device');
            // api/v0/devices/$hostname
            $app->get('/:hostname', 'authToken', 'get_device')->name('get_device');
            // api/v0/devices/$hostname
            $app->patch('/:hostname', 'authToken', 'update_device')->name('update_device_field');
            $app->get('/:hostname/vlans', 'authToken', 'get_vlans')->name('get_vlans');
            // api/v0/devices/$hostname/vlans
            $app->get('/:hostname/graphs', 'authToken', 'get_graphs')->name('get_graphs');
            // api/v0/devices/$hostname/graphs
            $app->get('/:hostname/ports', 'authToken', 'get_port_graphs')->name('get_port_graphs');
            $app->get('/:hostname/port_stack', 'authToken', 'get_port_stack')->name('get_port_stack');
            // api/v0/devices/$hostname/ports
            $app->get('/:hostname/components', 'authToken', 'get_components')->name('get_components');
            $app->post('/:hostname/components/:type', 'authToken', 'add_components')->name('add_components');
            $app->put('/:hostname/components', 'authToken', 'edit_components')->name('edit_components');
            $app->delete('/:hostname/components/:component', 'authToken', 'delete_components')->name('delete_components');
            $app->get('/:hostname/groups', 'authToken', 'get_device_groups')->name('get_device_groups');
            $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');
            // api/v0/devices/$hostname/$type
            $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname');
// =====================================================================
// =====================================================================
$app->get('/wares/:waretype/:wareid', function ($waretype, $wareid) use($app) {
    echo "Not implemented";
    $app->response->setStatus(501);
});
// =====================================================================
// =====================================================================
$app->put('/wares/:waretype/:wareid', function ($waretype, $wareid) use($app) {
    echo "Not implemented";
    $app->response->setStatus(501);
});
// =====================================================================
// =====================================================================
$app->patch('/wares/:waretype/:wareid', function ($waretype, $wareid) use($app) {
    echo "Not implemented";
    $app->response->setStatus(501);
});
// =====================================================================
// =====================================================================
$app->delete('/wares/:waretype/:wareid', function ($waretype, $wareid) use($app) {
    echo "Not implemented";
    $app->response->setStatus(501);
});
// =====================================================================
// =====================================================================
$app->get('/wares/:waretype/:wareid/git', function ($waretype, $wareid) use($app) {
    echo "Not implemented";
    $app->response->setStatus(501);
});
// =====================================================================
// =====================================================================
Example #5
0
     $emoji = Controllers\EmojiController::update($id, $putVars, 1);
     if (empty($emoji)) {
         $app->response->setStatus(304);
         $app->response->body('{"error" : "Not Modified."}');
         return $app->response();
     }
     $app->response->body($emoji);
     return $app->response();
 });
 // Partially update an emoji with ID.
 $app->patch('/:id', function ($id) use($app) {
     $patchVars = $app->request->getBody();
     $emoji = Controllers\EmojiController::update($id, $patchVars, 2);
     if (empty($emoji)) {
         $app->response->setStatus(304);
         $app->response->body('{"error" : "Not Modified."}');
         return $app->response();
     }
     $app->response->body($emoji);
     return $app->response();
 });
 // Delete emoji with ID.
 $app->delete('/:id', function ($id) use($app) {
     $prompt = Controllers\EmojiController::delete($id);
     if (!$prompt) {
         $app->response->setStatus(400);
         $app->response->body('{"error" : "Not deleted. Emoji does not exist."}');
         return $app->response();
     }
     $app->response->body('{"success" : "Emoji ' . $id . ' deleted successfully."}');
     return $app->response();
Example #6
0
    }
    if (isset($myArray)) {
        echo json_encode($myArray);
    } else {
        $myArray[] = NULL;
        echo json_encode($myArray);
    }
    $result->close();
    $mysqli->close();
});
/*Updates the a repair Item specified by an item id, in the first argument :item, and changes its name to :new_item*/
$app->patch('/repairItem/:item/:new_item', $check_token, function ($item, $new_item) {
    $mysqli = new mysqli("mysql.eecs.oregonstate.edu", "cs419-g4", "RNjFRsBYJK5DVF8d", "cs419-g4");
    $stmt = $mysqli->prepare("UPDATE repair_items SET itemName = ? WHERE itemId = ?");
    if (isset($params->itemName)) {
        $new_item = $mysqli->real_escape_string((string) $params->itemName);
    }
    $stmt->bind_param("si", $new_item, $item);
    $stmt->execute();
    echo $item, $new_item;
});
/*Adds a new Business to the repair_businesses database. Data must be provided to in JSON format:
         businessName - name of Business
         Address - address of Business
         city - city of Business
         state - state of Business
         zip - zip code of Business
         phone - phone number of Business
         website - website of Business (optional)
         hours - hours of Business (optional)
         addInfo - Additional Business info (optional)
  */