How to handle REST API call for GET Verb

Discussion in 'PHP' started by flipmedia, Sep 28, 2013.

  1. flipmedia

    flipmedia New Member

    Joined:
    Mar 21, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Dear pals,

    I am newbie in RESTful services . I need to call a GET Verb in Server . I know 2 methods

    1. Ajax Call

    we can write it as


    Code:
    $.ajax({
             url: url, 
             dataType: "html",
             type: 'POST', 
             data: "id="+id+"&type="+type, 
             success: function(data){ 
    		    //$("#content").html(data); 
    			alert(data);
    			$('table #sample-boxed-2-pagination th a').each(function(){
    				//this.href = this.href.replace(sub_url, main_url);
    				var value = this.href.split('?');
    				//alert(value[0]);
    				if(value[0]!=sub_url)
    				{
    				  this.href = this.href.replace(value[0], sub_url);
    				}
          });
             }
    		 
    		 
          });		 
    });
    But I know it's not working in Cross domain scenario . Please advise a method to work same in all domains .

    2. Using file_get_contents() function like

    Code:
    $response = file_get_contents('<url>?parm1=9');
    I know I can call POST verb using cURL as
    Code:
    $ch = curl_init();
    
    	curl_setopt($ch, CURLOPT_URL, "<base_url>/simple_rest_master/test");
    	curl_setopt($ch, CURLOPT_HEADER, 0);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_POST, 1);
    
    
    	$data = array(
    		'username' => 'foo',
    		'password' => 'bar'
    	);
    
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    
    	$contents = curl_exec($ch);
    
    	curl_close($ch);
    	
    	echo $contents;  // manipulate response
    Do you can advise the syntax of GET call using cURL ?

    Waiting your fast reply

    Thanks,

    Anes
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice