wernerdweight / curler
cURL helper for PHP
1.1.0
2019-12-08 21:33 UTC
Requires
- php: >=7.2.0
- thecodingmachine/safe: ^0.1.13
- wernerdweight/ra: ^1.0
Requires (Dev)
- thecodingmachine/phpstan-safe-rule: ^0.1.3
- wernerdweight/cs: ^1.3
README
cURL helper for PHP
Instalation
- Download using composer
composer require wernerdweight/curler
- Use in your project
use WernerDweight\Curler\Curler; use WernerDweight\Curler\Request; $curler = new Curler(); $request = (new Request()) ->setEndpoint('https://some-website.tld') ->setMethod('POST') ->setPayload(['key' => 'value']) ->setHeaders(['Accept: text/html', 'Accept-Encoding: gzip']) ->setAuthentication('user', 'password') ; $response = $curler->request($request); echo $response->text(); // '<html>...</html>' var_dump($response->getMetaData()); // array of response metadata (content-type, status...)
API
Curler
request(Request $request): Response
Allows to fetch data according to given$request
.
Request
setEndpoint(string $endpoint): self
getEndpoint(): ?string
setMethod(string $method): self
getMethod(): ?string
setPayload(array $payload): self
getPayload(): ?array
setHeaders(array $headers): self
addHeader(string $header): self
removeHeader(string $header): bool
getHeaders(): ?array
setAuthentication(string $user, string $password): self
getAuthentication(): ?array
setBearerAuthorization(string $token): self
Response
getMetaData(): WernerDweight\RA\RA
cURL info (see here).ok(): bool
Returns a boolean stating whether the response was successful (status in the range 200-299) or not.redirected(): bool
Returns whether or not the response is the result of a redirect; that is, redirect count is more than zero.status(): int
Returns the status code of the response (e.g., 200 for a success).contentType(): string
Returns the content type of the response (e.g., text/html).url(): string
Returns the URL of the response.text(): string
Returns the response as text.json(): WernerDweight\RA\RA
Returns the response as RA (see here).