Send PATCH request to a URL
public static patch ( string $url, array $headers = [], mixed $body = null, string $username = null, string $password = null ) : unirest\Response | ||
$url | string | URL to send the PATCH request to |
$headers | array | additional headers to send |
$body | mixed | PATCH body data |
$username | string | Basic Authentication username (deprecated) |
$password | string | Basic Authentication password (deprecated) |
return | unirest\Response |
public function testPatch() { $response = Request::patch('http://mockbin.com/request', array('Accept' => 'application/json'), array('name' => 'Mark', 'nick' => 'thefosk')); $this->assertEquals(200, $response->code); $this->assertEquals('PATCH', $response->body->method); $this->assertEquals('Mark', $response->body->postData->params->name); $this->assertEquals('thefosk', $response->body->postData->params->nick); }
/** * The underlying call to the Kong Server * * @throws \Ignittion\Kong\KongException when something goes wrong with the Http request * * @param string $verb * @param string $uri * @param array $options * @param array $body * @return \stdClass */ public function call($verb, $uri, array $params = [], array $body = [], array $headers = []) { $verb = strtoupper($verb); $api = "{$this->url}:{$this->port}/{$uri}"; $headers = array_merge($headers, ['Content-Type: application/json']); try { switch ($verb) { case 'GET': $request = RestClient::get($api, $headers, $params); break; case 'POST': $request = RestClient::post($api, $headers, $body); break; case 'PUT': $request = RestClient::put($api, $headers, $body); break; case 'PATCH': $request = RestClient::patch($api, $headers, $body); break; case 'DELETE': $request = RestClient::delete($api, $headers); break; default: throw new Exception('Unknown HTTP Request method.'); } } catch (Exception $e) { throw new KongException($e->getMessage()); } // save this request $this->body = $request->body; $this->headers = $request->headers; $this->httpCode = $request->code; $this->rawBody = $request->raw_body; // return a more simplified response $object = new stdClass(); $object->code = $this->httpCode; $object->data = $this->body; return $object; }