ApiService
in package
Table of Contents
Properties
- $client : mixed
Methods
- __construct() : mixed
- ApiService constructor
- deleteAsync() : array<string|int, mixed>
- Make a DELETE request to the given URL asynchronously
- get() : array<string|int, mixed>
- Make a GET request to the given URL
- getAsync() : array<string|int, mixed>
- Make a GET request to the given URL asynchronously
- handleResponse() : array<string|int, mixed>|string
- Handle the response from the request
- patchAsync() : array<string|int, mixed>
- Make a PATCH request to the given URL asynchronously
- post() : array<string|int, mixed>
- Make a POST request to the given URL
- postAsync() : array<string|int, mixed>
- Make a POST request to the given URL asynchronously
- putAsync() : array<string|int, mixed>
- Make a PUT request to the given URL asynchronously
- asyncRequest() : array<string|int, mixed>
- Make an asynchronous request to the given URL
- structureResponse() : array<string|int, mixed>
- Structure the response from the request
Properties
$client
protected
mixed
$client
Methods
__construct()
ApiService constructor
public
__construct([mixed $baseUrl = "http://localhost:9001/api/" ][, mixed $apiKey = null ]) : mixed
Parameters
- $baseUrl : mixed = "http://localhost:9001/api/"
- $apiKey : mixed = null
deleteAsync()
Make a DELETE request to the given URL asynchronously
public
deleteAsync(string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
get()
Make a GET request to the given URL
public
get(string $url) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
Return values
array<string|int, mixed> —- The response from the request
getAsync()
Make a GET request to the given URL asynchronously
public
getAsync(string $url) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
Return values
array<string|int, mixed> —- The response from the request
handleResponse()
Handle the response from the request
public
handleResponse(array<string|int, mixed> $response, string $errorMessage) : array<string|int, mixed>|string
Parameters
- $response : array<string|int, mixed>
-
- The response from the request
- $errorMessage : string
-
- The error message to throw if the request was not successful
Return values
array<string|int, mixed>|string —- The data from the response
patchAsync()
Make a PATCH request to the given URL asynchronously
public
patchAsync(string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
post()
Make a POST request to the given URL
public
post(string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
postAsync()
Make a POST request to the given URL asynchronously
public
postAsync(string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
putAsync()
Make a PUT request to the given URL asynchronously
public
putAsync(string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
asyncRequest()
Make an asynchronous request to the given URL
private
asyncRequest(string $method, string $url[, array<string|int, mixed> $body = [] ]) : array<string|int, mixed>
Parameters
- $method : string
-
- The HTTP method to use
- $url : string
-
- The URL to make the request to
- $body : array<string|int, mixed> = []
-
- The body to send with the request
Return values
array<string|int, mixed> —- The response from the request
structureResponse()
Structure the response from the request
private
structureResponse(bool $success, array<string|int, mixed>|string $data[, string $error = '' ]) : array<string|int, mixed>
Parameters
- $success : bool
-
- Whether the request was successful
- $data : array<string|int, mixed>|string
-
- The data from the request
- $error : string = ''
-
- The error message from the request
Return values
array<string|int, mixed> —- The structured response