PHPackages                             oh86/laravel-http-tools - 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. oh86/laravel-http-tools

ActiveLibrary

oh86/laravel-http-tools
=======================

some http tools for laravel framework

v1.1.1(3mo ago)01624MITPHP

Since Feb 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/OneHundred86/laravel-http-tools)[ Packagist](https://packagist.org/packages/oh86/laravel-http-tools)[ RSS](/packages/oh86-laravel-http-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (4)

### 用于laravel框架的http开发的工具

[](#用于laravel框架的http开发的工具)

#### 1.错误码配置

[](#1错误码配置)

```
// 编辑config/errorcode.php
return [
    'messages' => [
        0 => 'ok',
        1 => 'error',
        // ...
    ],
];
```

#### 2.json响应

[](#2json响应)

```
use Illuminate\Http\Request;
use Oh86\Http\Response\ErrorResponse;
use Oh86\Http\Response\OkResponse;

class XXXCtroller
{
    public function ok(Request $request)
    {
        return new OkResponse();
    }

    public function error(Request $request)
    {
        return new ErrorResponse(1, null, [
            'foo' => 'bar',
        ]);
    }
}
```

#### 3.异常

[](#3异常)

##### 3.1 错误码异常

[](#31-错误码异常)

```
use Oh86\Http\Exceptions\ErrorCodeException;

throw new throw new ErrorCodeException(401, null, null, 401); // 响应错误码为401的json响应。
```

##### 3.2 http请求错误异常

[](#32-http请求错误异常)

```
use Illuminate\Support\Facades\Http;
use Oh86\Http\Exceptions\HttpRequestException;

$url = 'https://api.test/test';
$datas = ['foo' => 'bar'];
$headers = ['X-Test' => 'test'];
$r = Http::withHeaders($headers)->get($url, $datas);

if ($response->json('code') !== 0) {
    // 将响应json响应给客户端
    throw new HttpRequestException(
        $r->status(),
        $r->body(),
        $url,
        $datas,
        $headers,
    );
}
```

#### 4.中间件

[](#4中间件)

#### 4.1 互斥锁中间件

[](#41-互斥锁中间件)

```
use Illuminate\Support\Facades\Route;
use Oh86\Http\Middleware\MutexRequestByArg;

Route::get('sms/code', [SmsController::class, 'sendSmsCode'])
    ->middleware(MutexRequestByArg::class.':phone');
```

#### 5.基于token的会话状态

[](#5基于token的会话状态)

```
use Oh86\Http\TokenSessions\AbstractTokenSession;

class TestToken extends AbstractTokenSession
{
    protected $storeKey = 'TestToken';
    protected $ttl = 300;
}

// 首次生成token
$t = new TestToken();
$t->put('foo', 'bar');
// $t->save(); // auto save in destructor
$token = $t->getToken();

// 其他地方使用token
$t = TestToken::load($token);
$val = $t->get('foo');
$t->destroy();  // 使用完手动销毁
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance88

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity40

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 ~182 days

Total

3

Last Release

92d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/oh86-laravel-http-tools/health.svg)

```
[![Health](https://phpackages.com/badges/oh86-laravel-http-tools/health.svg)](https://phpackages.com/packages/oh86-laravel-http-tools)
```

PHPackages © 2026

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