send GET , POST , PUT , PATCH , DELETE requests
send params in simple array
send headers in simple array
requests auto logging
error logger
send request without waiting for response
Go to your project root directory and run this command in terminal:
composer require arashabedii/requester
# to enable request logging just pass $logger=true to send method
Request::send([string] url, [array] or [string] or [file context] params, [string] request type , [array] headers,[bool] logger);
require 'vendor/autoload.php';
SEND GET REQUEST
<?php
use ArashAbedii\Request;
require './vendor/autoload.php';
#------------------------------SIMPLE GET REQUEST---------------------------
$url="https://reqres.in/api/users";
$method='GET';
$params=[
'delay'=>1,
];
$headers=[
'Content-Type'=>'application/json',
];
$logger=true; //enable or diable logging requests
$response=Request::send($url,$params,$method,$headers,$logger);
//show headers
echo $response->headers;
//show response body
echo $response->body;
SEND POST REQUEST
<?php
use ArashAbedii\Request;
require './vendor/autoload.php';
#------------------------------SIMPLE POST REQUEST---------------------------
$url="https://reqres.in/api/users";
$method='POST';
$params=[
'name'=>'myname',
'job'=>'myjob'
];
$headers=[
'Content-Type'=>'application/json',
];
$logger=false; //enable or diable logging requests
$response=Request::send($url,$params,$method,$headers,$logger);
//show headers
echo $response->headers;
//show response body
echo $response->body;
SEND PUT REQUEST
<?php
use ArashAbedii\Request;
require './vendor/autoload.php';
#------------------------------SIMPLE PUT REQUEST---------------------------
$url="https://reqres.in/api/users/2";
$method='PUT';
$params=[
'name'=>'myname2',
'job'=>'myjob2'
];
$headers=[
'Content-Type'=>'application/json',
];
$logger=false; //enable or diable logging requests
$response=Request::send($url,$params,$method,$headers,$logger);
//show headers
echo $response->headers;
//show response body
echo $response->body;
SEND PATCH REQUEST
<?php
use ArashAbedii\Request;
require './vendor/autoload.php';
#------------------------------SIMPLE PATCH REQUEST---------------------------
$url="https://reqres.in/api/users/2";
$method='PATCH';
$params=[
'name'=>'myname2',
'job'=>'myjob2'
];
$headers=[
'Content-Type'=>'application/json',
];
$logger=false; //enable or diable logging requests
$response=Request::send($url,$params,$method,$headers,$logger);
//show headers
echo $response->headers;
//show response body
echo $response->body;
SEND DELETE REQUEST
<?php
use ArashAbedii\Request;
require './vendor/autoload.php';
#------------------------------SIMPLE DELETE REQUEST---------------------------
$url="https://reqres.in/api/users/2";
$method='DELETE';
$params=[
//no params or your params
];
$headers=[
'Content-Type'=>'application/json',
];
$logger=true; //enable or diable logging requests
$response=Request::send($url,$params,$method,$headers,$logger);
//show headers
echo $response->headers;
//show response body
echo $response->body;