0

I'm using PHP 5.3, and trying to develop a simple web service that gets some parameters with POST method and has a response.

function start(){
    getAndValidateParams();

    global $response;
    echo json_encode($response);
}

function getAndValidateParams(){
    // token (mandatory)
    if(isset($_POST[PARAM_TOKEN])){
        echo 'got your token';
    }else{
        $response[ERROR_CODE] = ERR2_INVALID_TOKEN;
        $response[DESCRIPTION] = CODE2_DESC;
    }
}

I'm trying to test that with Postman: enter image description here

The problems:
1. About the Xdebug HTML I saw the following question, If I turn the var_dump off, will it disable usage of var_dump() inside my php code? (I want to be able use it for debugging but not seeing that in the response).

2.Also I have a problem to pass the parameter 'token', I don't see it in getAndValidateParams().

Any help will be appreciated.

1 Answer 1

1

I have used your function to just get insight in this and for tesing you can use also there is Advanced REST client in chrome similar to postMAN that you are using -- use the below lines to debug this --

function start(){
        $response = getAndValidateParams();
        return json_encode($response);
    }

// calling function ends here

// statrt another function that is being called 

function getAndValidateParams(){
    // token (mandatory)
    // print_r($_POST);die;  // just for debug purpose
    if(isset($_POST[PARAM_TOKEN])){
       $response[ERROR_CODE] = 0; 
       $response[DESCRIPTION] = "Success";
       $response[DEtail] = $yourdetailarr; // array of data that you want to retuen

    }else{
        $response[ERROR_CODE] = ERR2_INVALID_TOKEN;
        $response[DESCRIPTION] = CODE2_DESC;
    }
  return $response;
}
/// ends here

check the response here by calling start function .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.