PHPackages                             andrewdyer/php-actions - 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. andrewdyer/php-actions

ActiveLibrary[API Development](/categories/api)

andrewdyer/php-actions
======================

Framework-agnostic action utilities for building structured and predictable JSON API endpoints

02PHPCI passing

Since Mar 12Pushed 1mo agoCompare

[ Source](https://github.com/andrewdyer/php-actions)[ Packagist](https://packagist.org/packages/andrewdyer/php-actions)[ RSS](/packages/andrewdyer-php-actions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

🎬 Actions
=========

[](#-actions)

Framework-agnostic action utilities for building structured and predictable JSON API endpoints.

✨ Introduction
--------------

[](#-introduction)

This library adheres to standard HTTP messaging principles (PSR-compliant) and provides a small set of utilities to standardise how actions handle requests and generate responses. By establishing clear patterns for success responses and error payloads, it helps keep action classes focused on domain logic while giving clients predictable, well-structured JSON responses, regardless of the framework or HTTP layer used.

📥 Installation
--------------

[](#-installation)

```
composer require andrewdyer/php-actions
```

🚀 Getting Started
-----------------

[](#-getting-started)

The examples below demonstrate how this library can be used with [Slim Framework 4](https://www.slimframework.com/).

> ⚠️ Slim and a PSR-7 implementation are not included as dependencies of this package and must be installed separately before running these examples.

### 1. Create an action

[](#1-create-an-action)

The action below reads a route argument and returns either a success or error JSON payload.

```
declare(strict_types=1);

namespace App\Http\Actions;

use Anddye\Actions\AbstractAction;
use Anddye\Actions\Payloads\ActionError;
use Anddye\Actions\Payloads\ActionPayload;
use Psr\Http\Message\ResponseInterface;

final class PingAction extends AbstractAction
{
    protected function handle(): ResponseInterface
    {
        $mode = (string) $this->resolveArg('mode');

        if ($mode !== 'ok') {
            return $this->respondWithJson(
                ActionPayload::error(
                    ActionError::badRequest('Mode must be "ok".'),
                    400
                )
            );
        }

        return $this->respondWithJson(
            ActionPayload::success([
                'message' => 'pong',
            ])
        );
    }
}
```

### 2. Register the route

[](#2-register-the-route)

The action is wired into the Slim bootstrap so requests to `/ping/{mode}` are dispatched to the action class.

```
declare(strict_types=1);

use App\Http\Actions\PingAction;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

// If you're using a container, ensure PingAction is resolvable there.
$app->get('/ping/{mode}', PingAction::class);

$app->run();
```

📚 Usage
-------

[](#-usage)

Once the route is registered, Slim will invoke your action and return the payload as JSON.

```
GET /ping/ok
Accept: application/json

```

**200 OK**

```
{
  "data": {
    "message": "pong"
  }
}
```

```
GET /ping/nope
Accept: application/json

```

**400 Bad Request**

```
{
  "error": {
    "type": "BAD_REQUEST",
    "description": "Mode must be \"ok\"."
  }
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance58

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/andrewdyer-php-actions/health.svg)

```
[![Health](https://phpackages.com/badges/andrewdyer-php-actions/health.svg)](https://phpackages.com/packages/andrewdyer-php-actions)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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