PHPackages                             myoperator/transport - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. myoperator/transport

ActiveLibrary[HTTP &amp; Networking](/categories/http)

myoperator/transport
====================

Guzzle wrapper for making GET or POST or any network requests

1.3.1(6y ago)0105[1 PRs](https://github.com/myoperator/transport/pulls)GPL-3.0-or-laterPHPCI passing

Since Dec 5Pushed 3w ago1 watchersCompare

[ Source](https://github.com/myoperator/transport)[ Packagist](https://packagist.org/packages/myoperator/transport)[ RSS](/packages/myoperator-transport/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

[![Travis (.org) branch](https://camo.githubusercontent.com/77f2bac902b4633ed940d06e311ee23ae8647d0032d90096342dec10ea02f61a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f636f64656173617368752f7472616e73706f72743f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/77f2bac902b4633ed940d06e311ee23ae8647d0032d90096342dec10ea02f61a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f636f64656173617368752f7472616e73706f72743f7374796c653d666c61742d737175617265)[![Travis (.org) branch](https://camo.githubusercontent.com/bb110026fe586f19ecd8e29b4a106c95f295b7d054747e86d2aadc45533213a6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f64656173617368752f7472616e73706f72742f6d6173746572)](https://camo.githubusercontent.com/bb110026fe586f19ecd8e29b4a106c95f295b7d054747e86d2aadc45533213a6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f64656173617368752f7472616e73706f72742f6d6173746572)

MyOperator Transport
====================

[](#myoperator-transport)

This is a package that uses guzzle http transport and can be used to make network requests. This internally uses [Guzzle](https://github.com/guzzle/guzzle) library to make requests.

Quick Start
-----------

[](#quick-start)

To make a `GET` or `POST` requests:

```
include_once 'vendor/autoload.php';

use MyOperator\Transport\Transport;

$transport = new Transport('http://localhost/api');

// Making a simple GET request
$response = $transport->get('/users?a=b&c=d');

// More better GET request
$response = $transport->get('/users', ['a' => 'b', 'c' => 'd']);
// Equivalent to curl -XGET -H 'application/json' http://localhost/api/users?a=b&c=d

// To make a POST
$response = $transport->post('/users', ['a' => 'b']);
// Equivalent to curl -XPOST -d a=b -H 'application/json' http://localhost/api/users

// Response can be directly cast to string
echo (string) $response; // {"a" : "b"}

//Or json if you like
print_r($response->json()); // ['a' => 'b']

// Or plaintext, same like casting
echo $response->text(); //{"a": "b"}
```

Using Responses
---------------

[](#using-responses)

Responses are the main part of making any responses. Since responses can be of any type (i.e. json, xml, text etc) this library takes cares of automatically converting any json encodeable responses.

Responses are part of `MyOperator\Transport\Response`. Hence any response have three available methods:

- `json()` which returns array if response is valid json. Else the response is returned as is
- `text()` returns the text response as is
- `getStatus()` returns the response HTTP Status code

```
//Assuming webservice `/getjson` returns {'a': 'b'}
// and '/gettext' returns 'Simple text response'

$response = $transport->get('/getjson');
// assertTrue $response->json() == ['a' => 'b']
// assertTrue $response->text() == '{"a": "b"}'

$response = $transport->get('/gettext');
// assertTrue $response->json() == 'Simple text response'
// assertTrue $response->text() == 'Simple text response'
// assertTrue (string) $response == 'Simple text response'
```

Setting headers
---------------

[](#setting-headers)

Sometime, you may wish to add headers, which can be easily done using `setHeaders` method.

```
use MyOperator\Transport\Transport;

$transport = new Transport('http://localhost');

$transport->setHeaders(['X-Auth-key' => 'xyz']);

$transport->post('/login');
```

OAuth
-----

[](#oauth)

Many uses OAuth in day to day process. This library takes care of refreshing your access token. Please note that **this library does not generate your access token** but only refreshes it automatically, if some unauthorized status code is encountered.

Please read more here: [Oauth.md](./oauth.md)

### Mocking network requests

[](#mocking-network-requests)

This library aims at making writing unit tests and mocks a breeze. This library provides a fluent [Guzzle mock](http://docs.guzzlephp.org/en/stable/testing.html) api to make mocking easy.

To mock a network request, you can easily create a mock using `MyOperator\Transport\TransportMock`. Then can you queue some responses to it. You can then call your apis and the mock will replay the queues responses in order.

For instance, to mock a `200 SUCCESS` response from any api, you can do:

```
use MyOperator\Transport\TransportMock;

// Inititalising a mocker
$transport = new TransportMock();

//Creating custom response. order is createResponse($body, $headers= [], $status_code=200);
$mockResponse = $transport->createResponse(json_encode(['a' => 'b']));

// Creating another GuzzleHttp\Psr7\Response responses
$anotherResponse = new GuzzleHttp\Psr7\Response(201, [], json_encode(['c' => 'd']));

// Queue a valid GuzzleHttp\Psr7\Response
$transport->queue($mockResponse);
$transport->queue($anotherResponse);

// Finally we can start mock
$transport->mock();

// This will return first queued response, doesn't matter whatever the request is
$response = $transport->get('/get');
//assertTrue $response->json() == ['a' => 'b']
//assertTrue $response->getStatus() == 200

$response = $transport->post('/somethingelse');
//assertTrue $response->json() == ['c' => 'd']
//assertTrue $response->getStatus() == 201

// Since at this point we have exhaused our queued response,
// this will throw an \OutOfBoundsException
$response = $transport->get('/status');
```

TODO
----

[](#todo)

- Handling public and private APIs
- Setting basic authentication process

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance62

Regular maintenance activity

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2351d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/13e9ef65aca6c94519bd96b589043034c126905d9d219f0d1d2362c9a06482ff?d=identicon)[codeasashu](/maintainers/codeasashu)

---

Top Contributors

[![codeasashu](https://avatars.githubusercontent.com/u/1492350?v=4)](https://github.com/codeasashu "codeasashu (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

curlphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/myoperator-transport/health.svg)

```
[![Health](https://phpackages.com/badges/myoperator-transport/health.svg)](https://phpackages.com/packages/myoperator-transport)
```

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34170.2k2](/packages/onesignal-onesignal-php-api)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
