CustomClient
in package
Custom API client class
Table of Contents
- $headers : array<string|int, mixed>
- Headers
- $idempotencyKey : string
- Idempotence key
- $url : string
- Server host
- $traitDeleteAsPost : bool
- Trait DELETE requests as POST
- $traitPutAsPost : bool
- Trait PUT requests as POST
- __construct() : mixed
- Constructor
- getHeaders() : array<string|int, mixed>
- Method returns headers
- getIdempotencyKey() : string
- Method returns idempotency key
- getUrl() : string
- Method returns URL
- sendDeleteRequest() : mixed
- Method sends DELETE request to server
- sendGetRequest() : mixed
- Method sends GET request to server.
- sendPostRequest() : mixed
- Method sends POST request to server
- sendPutRequest() : mixed
- Method sends PUT request to server
- setDeleteTraitMethod() : void
- Method traits DELETE as POST
- setIdempotencyKey() : void
- Method sets idempotence key.
- setPutTraitMethod() : void
- Method traits PUT as POST
- setUrl() : void
- Method sets URL
- dispatchResult() : mixed
- Method gets result and validates it.
- getCommonHeaders() : array<string|int, mixed>
- Method returns common headers
- getFormHeaders() : array<string|int, mixed>
- Method compiles post headers
- sendFormRequest() : mixed
- Method sends request on server
- sendRequest() : array<string|int, mixed>
- Method send request to the URL
- assertUrl() : void
- Method asserts that $url is set
Properties
$headers
Headers
protected
array<string|int, mixed>
$headers
= []
$idempotencyKey
Idempotence key
protected
string
$idempotencyKey
= ''
$url
Server host
protected
string
$url
= ''
$traitDeleteAsPost
Trait DELETE requests as POST
private
bool
$traitDeleteAsPost
= false
$traitPutAsPost
Trait PUT requests as POST
private
bool
$traitPutAsPost
= false
Methods
__construct()
Constructor
public
__construct([string $url = '' ][, array<string|int, mixed> $headers = [] ]) : mixed
Parameters
- $url : string = ''
-
service URL
- $headers : array<string|int, mixed> = []
-
HTTP headers
Return values
mixed —getHeaders()
Method returns headers
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —Headers
getIdempotencyKey()
Method returns idempotency key
public
getIdempotencyKey() : string
Return values
string —Idempotency key
getUrl()
Method returns URL
public
getUrl() : string
Return values
string —URL
sendDeleteRequest()
Method sends DELETE request to server
public
sendDeleteRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $endpoint : string
-
Calling endpoint
- $data : array<string|int, mixed> = []
-
Request data
Return values
mixed —Result of the request
sendGetRequest()
Method sends GET request to server.
public
sendGetRequest(string $endpoint) : mixed
Parameters
- $endpoint : string
-
Calling endpoint.
Return values
mixed —Result of the remote call.
sendPostRequest()
Method sends POST request to server
public
sendPostRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $endpoint : string
-
Calling endpoint
- $data : array<string|int, mixed> = []
-
Request data
Return values
mixed —Result of the request
sendPutRequest()
Method sends PUT request to server
public
sendPutRequest(string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $endpoint : string
-
Calling endpoint
- $data : array<string|int, mixed> = []
-
Request data
Return values
mixed —Result of the request
setDeleteTraitMethod()
Method traits DELETE as POST
public
setDeleteTraitMethod(bool $flag) : void
Parameters
- $flag : bool
Return values
void —setIdempotencyKey()
Method sets idempotence key.
public
setIdempotencyKey(string $key) : void
To remove the key just call this method the second time with the '' parameter
Parameters
- $key : string
-
Idempotence key
Return values
void —setPutTraitMethod()
Method traits PUT as POST
public
setPutTraitMethod(bool $flag) : void
Parameters
- $flag : bool
Return values
void —setUrl()
Method sets URL
public
setUrl(string $url) : void
Parameters
- $url : string
-
URL
Return values
void —dispatchResult()
Method gets result and validates it.
protected
dispatchResult(string $url, int $code, mixed $body) : mixed
Parameters
- $url : string
-
request URL
- $code : int
-
response HTTP code
- $body : mixed
-
response body
Return values
mixed —Request result
getCommonHeaders()
Method returns common headers
protected
getCommonHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —Headers
getFormHeaders()
Method compiles post headers
protected
getFormHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —Header
sendFormRequest()
Method sends request on server
protected
sendFormRequest(string $method, string $endpoint[, mixed $data = [] ]) : mixed
Parameters
- $method : string
-
HTTP method (POST|PUT|DELETE)
- $endpoint : string
-
Calling endpoint
- $data : mixed = []
-
Request data @return mixed request result
Return values
mixed —sendRequest()
Method send request to the URL
protected
sendRequest(string $url, array<string|int, mixed> $headers, string $method[, array<string|int, mixed> $data = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
URL
- $headers : array<string|int, mixed>
-
Headers
- $method : string
-
Request HTTP Method
- $data : array<string|int, mixed> = []
-
Request data
Tags
Return values
array<string|int, mixed> —Response body and HTTP code
assertUrl()
Method asserts that $url is set
private
assertUrl() : void