Go REST
P

PHP

pfjo23 over 4 years ago 4255 views 2 replies

Hi,
can I use your REST API with PHP? In case, how must the PHP look like for creating a user?
Regards and thanks in advance.

2 replies
Z
zeevy over 4 years ago

You can curl lib inside the php to make the rest calls.
Sample bash curl request for the same is given in home page. You need to convert it into php equipment curl request.

Also you can use any third party lib for php

Z
zeevy over 4 years ago

try this

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://gorest.co.in/public/v2/users',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{"name":"Tenali Ramakrishna", "gender":"male", "email":"tenali.ramakrishna+03@15ce.com", "status":"active"}',
  CURLOPT_HTTPHEADER => array('Content-Type: application/json')
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;

Your reply

Markdown supported