feat: return response as assoc array

This commit is contained in:
Victor Westerlund 2023-06-01 11:17:46 +02:00
parent a2587624e5
commit 4054502b4a

View file

@ -112,19 +112,22 @@
return $rx;
}
// Create HTTP-like JSON with ["<endpoint>","<method>","[payload]"] and return
// respone from endpoint as ["<http_status_code", "<json_encoded_response_body>"]
// Call a Reflect endpoint and return response as assoc array
public function call(string $endpoint, Method|string $method = (__CLASS__)::HTTP_DEFAULT_METHOD, array $payload = null): array {
// Resolve string to enum
$method = $this::resolve_method($method);
// Call endpoint over UNIX socket
if ($this->_con === Connection::AF_UNIX) {
return json_decode($this->socket_txn(json_encode([
// Return response as assoc array
return json_decode($this->socket_txn(
// Send request as stringified JSON
json_encode([
$endpoint,
$method->value,
$payload
])));
])
), true);
}
// Call endpoint over HTTP