wernerdweight / curler
cURL helper for PHP
Installs: 115
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/wernerdweight/curler
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): selfgetEndpoint(): ?stringsetMethod(string $method): selfgetMethod(): ?stringsetPayload(array $payload): selfgetPayload(): ?arraysetHeaders(array $headers): selfaddHeader(string $header): selfremoveHeader(string $header): boolgetHeaders(): ?arraysetAuthentication(string $user, string $password): selfgetAuthentication(): ?arraysetBearerAuthorization(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\RAReturns the response as RA (see here).