PHPackages                             tripsy/api-wrapper - 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. [API Development](/categories/api)
4. /
5. tripsy/api-wrapper

ActiveLibrary[API Development](/categories/api)

tripsy/api-wrapper
==================

Wrapper for API response

v1.3(1y ago)1939MITPHPPHP ^7.3|^8.0

Since Apr 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Tripsy/api-wrapper)[ Packagist](https://packagist.org/packages/tripsy/api-wrapper)[ RSS](/packages/tripsy-api-wrapper/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Description
===========

[](#description)

This wrapper can be used to build requests, handle responses and also to create a standard response for a REST API.

Response will contain the following keys:

- success
    - return `true` if no errors are encountered
- message
    - return a `string` message which describe the response
- errors
    - return an `array` containing a detailed list with errors encountered
- data @return mixed
    - return `array` or `string` containing relevant data for the response
- meta @return array
    - optional additional info can be returned as an `array` as key / value pair

Requirements
============

[](#requirements)

This package has been build to be used in Laravel, but it doesn't have strong dependencies.

The package assumes the requests are made with `lluminate\Support\Facades\Http`

Recommendations:

- php &gt;= 7.3
- laravel/framework &gt;= 8.0

Install
=======

[](#install)

Require the package using composer:

```
  composer require tripsy/api-wrapper

```

Examples
========

[](#examples)

### Output response

[](#output-response)

```
use Tripsy\ApiWrapper\ApiWrapper;

function index(ApiWrapper $apiWrapper): JsonResponse
{
    $results = [];

    $apiWrapper->success(true);
    $apiWrapper->message(__('message.success'));
    $apiWrapper->data([
        'results' => $results,
        'count' => count($results),
    ]);

    return response()->json($apiWrapper->resultArray(), Response::HTTP_OK);
}

```

### POST request

[](#post-request)

```
use Tripsy\ApiWrapper\ApiWrapper;

function store(ApiWrapper $apiWrapper): string
{
    $apiWrapper->requestMethod('POST');
    $apiWrapper->requestUrl('https://request.url');

    $validate = true;

    if ($validate === false) {
        // the next line of code is not mandatory
        // by default value for `success` is false anyway
        $apiWrapper->success(false);

        $apiWrapper->message(__('message.error'));

        $apiWrapper->errors([
            'Sample error',
            'Another sample error',
        ]);

        $apiWrapper->pushMeta('source', 'my_method');
        $apiWrapper->pushMeta('reference', 'my_app');
    } else {
        $apiWrapper->requestParams([
            'name' => 'John',
            'age' => '34',
            'gender' => 'male',
        ]);

        $apiWrapper->requestHeaders('X_FORWARDED_FOR', '127.0.0.1');

        $apiWrapper->makeRequest(function () use ($apiWrapper) {
            return Http::asForm()
                ->withHeaders($apiWrapper->requestHeaders())
                ->withOptions([
                    'verify' => true,
                ])
                ->timeout(120)
                ->post($apiWrapper->requestUrl(), $apiWrapper->requestParams());
        });

        // `success` will be set as true within `makeRequest` to reflect if the API response status code was between 200 & 300
        if ($apiWrapper->success() === true) {
            $apiWrapper->data(json_decode($apiWrapper->data(), true));

            //handle `result`
            switch ($apiWrapper->getData('result')) {
                case 'success':
                    $apiWrapper->pushMeta('happy', 'yes');
                    break;
                case 'failed':
                    // since the API request was a success but didn't returned the expected result
                    $apiWrapper->success(false);

                    $apiWrapper->pushMeta('happy', 'no');

                    $apiWrapper->message(__('message.failed'));
                    break;
                default:
                    $apiWrapper->pushMeta('happy', '?');

                    $apiWrapper->success(false);
                    $apiWrapper->message(__('message.result_not_defined'));
                    break;
            }
        }
    }

    return $apiWrapper->resultJson();
}

```

### Another POST request

[](#another-post-request)

```
use Tripsy\ApiWrapper\ApiWrapper;

function query(ApiWrapper $apiWrapper): array
{
    $apiWrapper->requestMethod('POST');
    $apiWrapper->requestUrl('https://request.url');
    $apiWrapper->requestHeaders('Content-Type', 'application/json');
    $apiWrapper->requestHeaders('Accept', 'application/json');
    $apiWrapper->requestParams([
        'formData' => [
            'name' => 'John',
            'age' => '34',
            'gender' => 'male',
        ],
        'sourceData' => [
            'website' => config('app.url'),
            'environment' => config('app.env'),
            'ipAddress' => '127.0.0.1',
        ],
    ]);

    //$apiWrapper->debug(true);
    $apiWrapper->makeRequest(function () use ($apiWrapper) {
        return Http::withToken('your_secret_token')
            ->withHeaders($apiWrapper->requestHeaders())
            ->withOptions([
                'verify' => true,
            ])
            ->post($apiWrapper->requestUrl(), $apiWrapper->requestParams());
    });

    $responseType = $apiWrapper->getMeta('responseType');

    if (config('app.env') == 'production') {
        if ($responseType == 'hidden') {
            return [];
        }
    }

    return $apiWrapper->resultArray();
}

```

### GET request

[](#get-request)

```
use Tripsy\ApiWrapper\ApiWrapper;

function query(ApiWrapper $apiWrapper): array
{
    $ipAddress = '192.168.0.1';

    $apiWrapper->requestMethod('GET');
    $apiWrapper->requestUrl('https://request.url/location/'.urlencode($ipAddress));
    $apiWrapper->requestHeaders('Accept', 'application/json');

    $apiWrapper->makeRequest(function () use ($apiWrapper) {
        return Http::withToken('your_secret_token')
            ->withHeaders($apiWrapper->requestHeaders())
            ->withOptions([
                'verify' => true,
            ])
            ->get($apiWrapper->requestUrl(), $apiWrapper->requestParams());
    });

    if ($apiWrapper->success() === false) {
        Log::channel('test')->info($apiWrapper->message());
    }
}

```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~130 days

Total

3

Last Release

542d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f49d87d1d9ab7676fadea9df71025d5aace1161b51641158b1de8aadbfa1bb1c?d=identicon)[Tripsy](/maintainers/Tripsy)

---

Top Contributors

[![Tripsy](https://avatars.githubusercontent.com/u/23176193?v=4)](https://github.com/Tripsy "Tripsy (4 commits)")

---

Tags

responserequestapilaravel

### Embed Badge

![Health badge](/badges/tripsy-api-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/tripsy-api-wrapper/health.svg)](https://phpackages.com/packages/tripsy-api-wrapper)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

3.0k37.6M134](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k14.2M63](/packages/knuckleswtf-scribe)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k9.5M89](/packages/openai-php-laravel)[statamic/cms

The Statamic CMS Core Package

4.8k3.6M986](/packages/statamic-cms)[kyon147/laravel-shopify

Shopify package for Laravel to aide in app development

485302.1k](/packages/kyon147-laravel-shopify)[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

74331.3k1](/packages/mozex-anthropic-laravel)

PHPackages © 2026

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