How make web services in Drupal?

Comments

meetpachchigar’s picture

You can use Drupal module.
https://www.drupal.org/project/services

mansigajjar’s picture

Hello,

You can create your own web services by using php curl header authentication.
You can follow below step to create web services.

For example : Get latest 10 basic page

1)Create new file curl.php and write below code

    @header('Content-type: application/json; charset=utf-8'); //set header type json
	$url	=	"http://example.com/page.php?limit=10&page=0"; 

	$ch = curl_init(); //initialize curl
	curl_setopt($ch, CURLOPT_URL, $url); 
	curl_setopt($ch, CURLOPT_USERPWD, "username:password"); //write here user credential
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, '3');
	$content = trim(curl_exec($ch));
	curl_close($ch);
	print_r($content);

2) Create new file page.php and write below code in page.php file


        $node_entity_field_query = new EntityFieldQuery();	
	$query = $node_entity_field_query->entityCondition('entity_type', 'node')
		     ->entityCondition('bundle', 'page')
		     ->propertyCondition('status', 1)
		     ->range(0,10)
		     ->execute();
	$node_resultset = array();
									
	if(is_array($query['node']) && !empty($query['node'])){
		$node_resultset = entity_load('node', array_keys($query['node']));
	}
    
     echo json_decode($node_resultset);
mahapatra.tusar’s picture

Can I use $url as facebook url, if possible then please send one url which I will got better output for understanding.

mansigajjar’s picture

Yes, you can use facebook url. Right now I don't have any URL.