VOOZH about

URL: https://deepwiki.com/hypervel/api-client/3-quick-start

⇱ Quick Start | hypervel/api-client | DeepWiki


Loading...
Menu

Quick Start

This page provides a simple working example demonstrating how to create an API client and make basic requests. It covers the minimal steps required to get started with the Hypervel API Client.

For detailed information about configuration options, see Configuration Reference. For advanced middleware setup and request customization, see Making Requests and Middleware System.


Purpose and Scope

This guide walks through the fundamental usage pattern: instantiating an ApiClient, making HTTP requests, and accessing response data. The examples demonstrate the core request lifecycle using the library's fluent interface.


Basic Client Instantiation

The ApiClient class serves as the entry point for all API interactions. You create an instance by extending this class and optionally configuring middleware, resources, and other options.


The client delegates method calls to a PendingRequest instance through the __call magic method at src/ApiClient.php41-45 This enables a fluent interface for building and sending requests.

Sources: src/ApiClient.php14-116


Making a GET Request

The simplest operation is a GET request. The client exposes HTTP verb methods (get, post, put, patch, delete, head) that create and execute requests.


Request Flow


The get() method is defined at src/PendingRequest.php175-178 and internally calls sendRequest() at src/PendingRequest.php265-291 which orchestrates the entire request lifecycle including middleware execution and response transformation.

Sources: src/ApiClient.php41-45 src/PendingRequest.php175-178 src/PendingRequest.php265-291


Accessing Response Data

The request methods return an ApiResource instance that provides multiple ways to access the response data:

Array Access


The ApiResource class implements ArrayAccess at src/ApiResource.php119-146 delegating to the underlying ApiResponse object.

Object Property Access


Property access is handled by the __get() magic method at src/ApiResource.php55-58

Array Conversion


The toArray() method at src/ApiResource.php103-106 returns the JSON-decoded response body.

Method Delegation


The ApiResource class delegates method calls to the underlying ApiResponse via the __call() method at src/ApiResource.php63-72

Sources: src/ApiResource.php18-147


Making a POST Request

POST requests follow the same pattern, accepting a data payload that will be serialized as JSON by default:


The post() method is defined at src/PendingRequest.php197-200 and accepts an array or JsonSerializable object as the data payload.

Core Classes Involved

ClassLocationRole
ApiClientsrc/ApiClient.php14Entry point; delegates to PendingRequest
PendingRequestsrc/PendingRequest.php22Orchestrates request building and execution
ApiRequestReferenced in src/PendingRequest.php273PSR-7 request wrapper
ApiResponseReferenced in src/PendingRequest.php284PSR-7 response wrapper
ApiResourcesrc/ApiResource.php18Response data container with convenient accessors

Sources: src/PendingRequest.php197-200 src/PendingRequest.php265-291


Request Lifecycle Overview

The following diagram shows how method calls flow through the core components during a typical request:


The __call() magic method at src/ApiClient.php41-45 intercepts the get() call and forwards it to a PendingRequest instance created by getClient() at src/ApiClient.php112-115 The PendingRequest::get() method at src/PendingRequest.php175-178 delegates to sendRequest() at src/PendingRequest.php265-291 which executes the HTTP request and transforms the response into an ApiResource.

Sources: src/ApiClient.php41-45 src/ApiClient.php112-115 src/PendingRequest.php175-178 src/PendingRequest.php265-291


Fluent Request Building

The PendingRequest class supports method chaining for configuring requests before execution. This is enabled by the __call() method at src/PendingRequest.php257-263 which delegates to the underlying HTTP client:


These configuration methods are forwarded to the underlying ClientPendingRequest from the hypervel/http-client package, as indicated by the @mixin annotation at src/PendingRequest.php20

Sources: src/PendingRequest.php257-263


Next Steps

Now that you understand the basic request flow, explore these topics for more advanced usage:

Sources: src/ApiClient.php14-116 src/PendingRequest.php22-342 src/ApiResource.php18-147