victorycodedev/nativephp-fetch
Fetch-style HTTP client for NativePHP, giving native desktop apps a simple, familiar way to make requests. Lightweight and Laravel-friendly, it aims to streamline pulling remote data into your native windows without leaving the ecosystem you already know.
Architecture fit
NativePHP Fetch sits between a Laravel application and the host platform's native HTTP stack, exposing a fluent, Laravel-HTTP-client-shaped API (Fetch:: facade, requests, retries, downloads, fakes) and dispatching lifecycle events into NativeComponents via #[On]. v1.1.0 strengthens the architectural fit in three ways:
Http::macro, Response::macro, and named routes — low conceptual overhead, high reuse.Fetch::baseUrl() with relative URLs, query strings, and downloads) codify environment-based endpoint configuration (dev/staging/prod, per-tenant hosts) as a first-class concept instead of string concatenation scattered across call sites.FetchRequestStarted, FetchRequestCompleted, FetchRequestFailed) now surface on Laravel's event dispatcher while remaining compatible with #[On] in NativeComponents. This is the most architecturally significant change: it enables cross-cutting concerns — telemetry, audit logging, token refresh, offline queueing, global error toasts — to be implemented once in the Laravel layer rather than duplicated per component. That is a genuine separation-of-concerns improvement for native app codebases where the UI layer and transport layer were previously coupled.Response helpers (created(), notFound(), unauthorized(), unprocessableEntity(), tooManyRequests(), statusIs()) are cosmetic-to-moderate: they improve readability and reduce magic-number drift, but they don't alter the architecture.
Integration feasibility
High, with caveats. The package is opt-in, additive, and explicitly backward compatible — all existing request APIs, #[On] events, retries, downloads, fakes, and native behavior are unchanged. No migration work is strictly required to adopt v1.1.0.
Adoption effort per capability:
statusIs(): near-zero. Mechanical, safe, can be adopted opportunistically during unrelated edits.FetchRequestStarted listener doing logging or DB writes becomes a per-request hot path.Technical risk Overall: low, with three concentrated areas.
fake() scenarios and surprise existing tests. Validate against the existing test suite, not just the changelog.Lower-severity: response helper naming collisions with existing internal helpers, and macro registration order affecting override behavior.
Key questions
Fetch fakes in tests? If so, existing tests with listeners registered may behave unexpectedly.FetchRequestFailed dispatched on retry exhaustion only, or on every failed attempt? This determines whether failure listeners can double-count.Fetch::baseUrl() interact with absolute URLs passed to the same client — ignored, error, or override?#[On] component-event pattern now that Laravel events are supported — is one canonical?Stack fit
Assumes a Laravel + NativePHP application with NativeComponents. Fetch is the native-transport client; v1.1.0 makes it behave more like the Laravel HTTP client teams already know (Http::macro, global events, fluent status helpers), which reduces the learning delta for PHP developers moving into native app work. No new runtime dependencies, no new infrastructure, no schema changes — this is a library-level release, not a platform shift.
Migration path No forced migration. Recommended path is progressive adoption, not a version bump project:
statusIs() opportunistically — these are pure readability wins with no design commitment.Fetch::baseUrl() in one client/service at a time, starting with the least critical integration, and verify query-parameter and download paths explicitly.Compatibility
#[On] component events, retries, downloads, fakes, and native behavior are preserved — so #[On] and Laravel events can coexist, which allows incremental listener migration rather than a flag day.Sequencing
Phase 1 (low risk, immediate): upgrade + regression validation; adopt statusIs() and response helpers. Phase 2 (low risk, config work): base URLs per environment, audited for query-string and download cases. Phase 3 (moderate): macro extraction with a naming/scoping convention and a credential-handling rule. Phase 4 (moderate, highest leverage): global lifecycle listeners — telemetry and logging first, then auth refresh and failure UX. Phase 5: retire duplicate per-component #[On] handlers where the global listener is now authoritative.
Do not sequence Phase 4 before Phase 2/3 if listeners will depend on the resolved base URL or macro-applied config; ordering avoids rework.
Maintenance Net positive, with a new artifact to own. Macros and base URLs centralize configuration that was previously duplicated per call site, which reduces the surface area for "one endpoint is missing the auth header" defects and shrinks the blast radius of an API base-URL change to a single line. Response helpers remove magic-number drift. The cost is a new piece of shared infrastructure: the macro registry and base-URL configuration become things that must be reviewed, versioned, and documented, and a bad macro now breaks every consumer at once. Assign a clear owner for the registry and treat changes to it like changes to a shared library.
Support Support surface is roughly unchanged for end users; the release reduces the "why does this one request behave differently" class of tickets by giving failures a single observable hook. Support burden shifts internally: the team must be able to answer "which listeners ran on that request" and "which macro applied that header." That implies documentation of macro names and listener purposes, plus log correlation IDs propagated through the lifecycle events. Expect a short ramp of questions during macro rollout, then a decline.
Scaling Two dimensions:
FetchRequestStarted. Treat the failure listener's event volume as a monitoring metric in its own right.Failure modes
FetchRequestFailed fires per attempt rather than per exhausted request, alerting and retry dashboards will over-report. Confirm semantics before building SLOs on it.Fetch fakes, tests may pass while listener behavior in production differs, or event assertions may become brittle. Validate the fake/event interaction early.#[On] and Laravel events both supported, duplicate handling is a realistic near-term failure mode — the same request producing two telemetry records or two toasts. Track which handlers have migrated.Ramp-up
Low for individual contributors: the helpers and statusIs() are self-documenting, and macros mirror the Http::macro idiom most Laravel developers already know. The steeper curve is for whoever owns the shared layer — deciding macro boundaries, base-URL strategy, and listener design — and for on-call, who need a mental model of the request lifecycle to diagnose failures now that behavior is spread across listeners rather than colocated in components. Budget roughly a short onboarding session plus written conventions for the macro registry and event listeners; that documentation is the main enablement deliverable of this upgrade, not the code changes themselves. Overall ramp-up cost is modest and front-loaded, and the consolidation this release enables should reduce long-term cognitive load in native component code.
How can I help you explore Laravel packages today?