Search code examples
resturl-encoding

Does REST API uses url encoding?


Does RESTful APIs provides url encoding as default or do I have to encode it using other methods? I am using following code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);    
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "xmlRequest=" . $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);

Solution

  • There is no 'standard REST'. So it's often very difficult to say something specific, because in some ways it's just an idea.

    But if you restrict REST to HTTP apis, generally the 'best practice' is that you use url encoding, where this is expected/needed by HTTP and don't use url encoding where it's unexpected.

    To get a better answer, rephrase the question with a specific example that made you wonder about this.