AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 5.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Origin
  • ACL

    • Introduction
    • How to install
    • Setup
    • Permissions
    • Roles
    • Users
    • Cached Permissions
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Collections

    • Collections
    • How to install
    • Summation

      • Summation Collection
      • Items Processor
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • Container
    • List Resolver
  • Core

    • Athenaeum Core Application
    • Prerequisite
    • How to install
    • Integration
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Database

    • Introduction
    • How to install
    • Models

      • Instantiatable
      • Sluggable
    • Query

      • Criteria (Query Filter)
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Filters

    • Search Filter Utilities
    • Prerequisites
    • How to install
    • Setup
    • Processor
    • Filters Builder
    • Predefined Resources

      • Search Processor
      • Sorting Processor
      • Constraints Processor
      • Matching Processor
    • Tip: Create a base builder
  • Http

    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Middleware
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Debugging
        • Logging
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
    • Messages

      • Http Messages
      • How to install
      • Serializers
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Redmine

    • Redmine Api Client
    • How to install
    • Setup
    • General Usage

      • Supported Operations
      • Fetch list of resources
      • Find
      • Fetch
      • Create new record
      • Update existing record
      • Delete existing record
      • Relations
    • Available Resources

      • Predefined Resources
      • Attachments
      • Enumerations
      • Issue Relations
      • Users
      • User Groups
      • Roles
      • Project Memberships
      • Versions (Milestones)
      • Issue Categories
      • Trackers
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Utils

    • Introduction
    • How to install
    • Array
    • Duration
    • Json
    • Math
    • Method Helper
    • Populatable
    • Version
  • Validation

    • Introduction
    • How to install
    • Setup
    • Rules

      • Alpha-Dash-Dot
You are viewing documentation for an outdated version. It is no longer supported!

Basic Usage

  • Obtain Http Client
  • Obtain Specific Client Profile
  • Fresh Client instance
  • Perform Http Requests
    • GET
    • HEAD
    • POST
    • PUT
    • DELETE
    • OPTIONS
    • PATCH
    • Generic Request

Obtain Http Client

To obtain a Http Client instance, use the HttpClientsManager. It can be obtained via HttpClientsManagerTrait.

<?php
use Aedart\Http\Clients\Traits\HttpClientsManagerTrait;

class WeatherController
{
    use HttpClientsManagerTrait;
    
    public function index()
    {
        $client = $this->getHttpClientsManager()->profile();
        
        // ...remaining not shown
    }
}

Obtain Specific Client Profile

In order to obtain a Http Client profile, state the profile name as argument for the profile() method.

$myClient = $this->getHttpClientsManager()->profile('my-client-profile');

Fresh Client instance

Available since v5.19.0

The profile() method will return the same Client instance, if it was previously requested (it caches the created instance for the profile name). If you need a fresh instance, without having it cached by the client manager, then use the fresh() method.

$client = $this->getHttpClientsManager()->fresh('my-client-profile');

Perform Http Requests

Each method that performs a request will return a PSR-7 ResponseInterface.

GET

Use get() to make a Http GET request.

$response = $client->get('/users');

HEAD

Use head() to make a Http HEAD request.

$response = $client->head('/users');

POST

Use post() to make a Http POST request.

$response = $client->post('/users', [
    'name' => 'John Doe',
    'job'  => 'developer'
]);

PUT

Use put() to make a Http PUT request.

$response = $client->put('/users/421', [
    'name' => 'Jim Orion',
    'job'  => 'architect'
]);

DELETE

Use delete() to make a Http DELETE request.

$response = $client->delete('/users/7742');

OPTIONS

Use options() to make a Http OPTIONS request.

$response = $client->options('/users');

PATCH

Use patch() to make a Http PATCH request.

$response = $client->patch('/users/4487', [
    'name' => 'Isabella Amelia Thomason',
    'job'  => 'lead designer'
]);

Generic Request

The request() method allows you to perform a generic Http request. It accepts three arguments:

  • $method: string Http method name
  • $uri: string or UriInterface The Uri
  • $options: array Driver specific request options (See Guzzle's documentation for additional information)
$response = $client->request('PATCH', '/users/1247', [
    'json' => [
        'name' => 'Emma Jackson',
        'job'  => 'junior developer'
    ]
]);
Edit page
Last Updated: 05/04/2022, 21:01
Contributors: Alin Eugen Deac, alin
Prev
Setup