Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Unirest Php Laravel Package

apimatic/unirest-php

Lightweight PHP HTTP client for making REST calls with minimal setup. Includes support for common verbs, headers, query params, JSON bodies, timeouts, and basic response handling. Useful for quick API integrations and scripts.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing via Composer: composer require apimatic/unirest-php. Then immediately use one of the HTTP verb shortcuts — Unirest::get(), Unirest::post(), etc. — to make your first call. For example:

$response = \Unirest\Request::get('https://api.example.com/users', ['Accept' => 'application/json']);
echo $response->code;     // HTTP status
echo $response->headers['Content-Type'];
echo $response->body;     // Raw response string (JSON string unless auto-decoded)

Check the src/ folder for the Request and Response classes, and review the examples/ (if present) to see common patterns. Since the package is minimal, the main entrypoint is Unirest\Request::{verb}() — start there before exploring lower-level configuration.

Implementation Patterns

  • Quick API Prototyping: Use inline requests in CLI tools or seed scripts (php artisan tinker with Unirest::post()). No middleware, no async — just get(), post() with associative arrays for body/params.
  • JSON Payloads & Parsing: Pass arrays as the body; the client automatically JSON-encodes them and sets Content-Type: application/json. Response body is a parsed PHP array or object (via json_decode) — use $response->body['data'] directly.
  • Custom Headers & Query Params: Pass headers as the second arg; query params can be appended to the URL or passed in the body for POST/PUT (check API docs — some expect query params even on non-GET requests).
  • Timeout & SSL Control: Use Unirest::setDefaultOption() to configure persistent settings (e.g., curl_options for SSL verification, timeout, connect_timeout) across all requests in a request lifecycle — ideal for consistent retry behavior or local dev (disable verify_peer cautiously).
  • Asynchronous Not Required: This is synchronous only; for batch requests, wrap calls in loops or a custom retry utility (e.g., 3 retries with exponential backoff using sleep()).

Gotchas and Tips

  • JSON Decoding Quirk: By default, body is auto-decoded if Content-Type contains json. Disable with Unirest::setDefaultOption('decoder', 'json'); or set to null to get raw strings. Verify with gettype($response->body) — unexpected string means decoding failed or was skipped.
  • No Built-in Retry Logic: Handle retries manually with try/catch around Unirest::*() calls; cURL throws exceptions for network errors (Unirest\Exception), not HTTP error codes (4xx/5xx). Always inspect $response->code.
  • Encoding Pitfall: For form POSTs, Unirest::post($url, $headers, $body) sends application/x-www-form-urlencoded only if $body is an array. For multipart/form-data, pass an array with file resources (new CURLFile(...)).
  • Testing Tip: Stub the client using dependency injection (e.g., inject a UnirestClient wrapper class) — mocking the Request class directly is harder due to static methods.
  • Security: Always validate and sanitize URLs passed to get(). Never inject user input directly into the URL without urlencode() for query parts. Disable SSL verification (verify_peer => false) only in dev — never in production.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4