src/Rest/SdkTrait.php
public function transporterAction(): Response
    {
        // Get all router params
        $routeParams = $this->router->getParams();

        // Confirm that an API version has been configured
        if (!array_key_exists('version', $routeParams)) {
            return $this->response->setJsonContent([
                'error' => 'You must specify an API version in your configuration.',
            ])->send();
        }

        // Confirm that the API version matches with the configuration.
        if ($routeParams['version'] != $this->apiVersion) {
            return $this->response->setJsonContent([
                'error' => 'The specified API version is different from your configuration.',
            ])->send();
        }

        // Get real API URL
        $apiUrl = getenv('EXT_API_URL') . str_replace('api/', '', $this->router->getRewriteUri());

        // Execute the request, providing the URL, the request method and the data.
        $response = $this->makeRequest($apiUrl, $this->request->getMethod(), $this->getData(), $this->apiHeaders);

        //set status code so we can get 404
        if ($response->getStatusCode()) {
            $this->response->setStatusCode($response->getStatusCode());
        }

        //Set all the response headers
        foreach ($response->getHeaders() as $header => $value) {
            // Set the response headers based on the response headers of the API.
            if (is_array($value)) {
                $value = current($value);
            }

            $this->response->setHeader($header, $value);
        }

        return $this->response->setContent($response->getBody());
    }
public function transporterAction(): Response
    {
        // Get all router params
        $routeParams = $this->router->getParams();

        // Confirm that an API version has been configured
        if (!array_key_exists('version', $routeParams)) {
            return $this->response->setJsonContent([
                'error' => 'You must specify an API version in your configuration.',
            ])->send();
        }

        // Confirm that the API version matches with the configuration.
        if ($routeParams['version'] != $this->apiVersion) {
            return $this->response->setJsonContent([
                'error' => 'The specified API version is different from your configuration.',
            ])->send();
        }

        // Get real API URL
        $apiUrl = getenv('EXT_API_URL') . str_replace('api/', '', $this->router->getRewriteUri());

        // Execute the request, providing the URL, the request method and the data.
        $response = $this->makeRequest($apiUrl, $this->request->getMethod(), $this->getData(), $this->apiHeaders);

        //set status code so we can get 404
        if ($response->getStatusCode()) {
            $this->response->setStatusCode($response->getStatusCode());
        }

        //Set all the response headers
        foreach ($response->getHeaders() as $header => $value) {
            // Set the response headers based on the response headers of the API.
            if (is_array($value)) {
                $value = current($value);
            }

            $this->response->setHeader($header, $value);
        }

        return $this->response->setContent($response->getBody());
    }
public function transporterAction ( ) : Response { // Get all router params $ routeParams = $ this -> router -> getParams ( ) ; // Confirm that an API version has been configured if ( ! array_key_exists ( 'version' , $ routeParams ) ) { return $ this -> response -> setJsonContent ( [ 'error' => 'You must specify an API version in your configuration.' , ] ) -> send ( ) ; } // Confirm that the API version matches with the configuration. if ( $ routeParams [ 'version' ] != $ this -> apiVersion ) { return $ this -> response -> setJsonContent ( [ 'error' => 'The specified API version is different from your configuration.' , ] ) -> send ( ) ; } // Get real API URL $ apiUrl = getenv ( 'EXT_API_URL' ) . str_replace ( 'api/' , '' , $ this -> router -> getRewriteUri ( ) ) ; // Execute the request, providing the URL, the request method and the data. $ response = $ this -> makeRequest ( $ apiUrl , $ this -> request -> getMethod ( ) , $ this -> getData ( ) , $ this -> apiHeaders ) ; //set status code so we can get 404 if ( $ response -> getStatusCode ( ) ) { $ this -> response -> setStatusCode ( $ response -> getStatusCode ( ) ) ; } //Set all the response headers foreach ( $ response -> getHeaders ( ) as $ header => $ value ) { // Set the response headers based on the response headers of the API. if ( is_array ( $ value ) ) { $ value = current ( $ value ) ; } $ this -> response -> setHeader ( $ header , $ value ) ; } return $ this -> response -> setContent ( $ response -> getBody ( ) ) ; }
Function tasked with delegating API requests to the configured API

@todo Verify headers being received from the API response before returning the request response.

@return \Phalcon\Http\Response
Function tasked with delegating API requests to the configured API