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 1w 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 today

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

22

—

LowBetter than 25% of packages

Maintenance64

Regular maintenance activity

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

[google/apiclient

Client library for Google APIs

9.8k186.9M875](/packages/google-apiclient)[stripe/stripe-php

Stripe PHP Library

4.0k139.3M411](/packages/stripe-stripe-php)[webonyx/graphql-php

A PHP port of GraphQL reference implementation

4.7k75.4M270](/packages/webonyx-graphql-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k90.6M248](/packages/twilio-sdk)[friendsofsymfony/jsrouting-bundle

A pretty nice way to expose your Symfony routing to client applications.

1.5k52.7M205](/packages/friendsofsymfony-jsrouting-bundle)[knplabs/github-api

GitHub API v3 client

2.2k15.3M170](/packages/knplabs-github-api)

PHPackages © 2026

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