Same thing without curl as a dependency (for the newbies who don’t know about the excellent PHP’s streams API):

$data = array(‘name’ => ‘Hagrid’, ‘age’ => ’36’);
$data_string = json_encode($data);

$result = file_get_contents(‘http://api.local/rest/users’, null, stream_context_create(array(
‘http’ => array(
‘method’ => ‘POST’,
‘header’ => ‘Content-Type: application/json’ . “\r\n”
. ‘Content-Length: ‘ . strlen($data_string) . “\r\n”,
‘content’ => $data_string,
),
)));