Welcome Guest, Not a member yet? Register   Sign In
API endpoint
#1

Hello world,

I'm building an API with philsturgeon's rest server.

My current controller is

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require(
APPPATH.'modules/api/libraries/REST_Controller.php');

class 
Service extends REST_Controller {
    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->library('service/vps/vpsmanager');
    }
    public function 
index_get()
    {
        
$this->response("This request is not available. See documentation.",400);
    }
    public function 
vps_get()
    {
        
$id $this->get('id');
        
$userID $this->apimanager->getUserIDFromKey($_SERVER['HTTP_X_API_KEY']);
        if(empty(
$id))
        {
            
$services $this->vpsmanager->getAllFromUID($userID);
            
$this->response(json_encode($services), 200);
        }
        else
        {
            if(
$this->vpsmanager->getServiceOwner($id) == $userID) {
                
$service $this->vpsmanager->getServiceData($id);
                
$this->response(json_encode($service), 200);
            }
            else
                
$this->response("this vps is not your"403);
        }
    }
    public function 
vps_start_post()
    {
        
$this->response("start");
    }


An url like http://localhost/api/v1/vps?=1 works, I got the data in the vps_get function.

Now I would like to do http://localhost/api/v1/vps/start?=1 or something in the same category.

Any idea how can we dev API subendpoint ?

Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB