Search by

denetorus / galaxy-application-rest-api

Denetorus

Runs PHP controller actions for HTTP requests and presents their results as JSON.

Package info

github.com/Denetorus/GalaxyApplicationRestApi

pkg:composer/denetorus/galaxy-application-rest-api

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-12-03 15:23 UTC

This package is auto-updated.

Last update: 2026-12-03 16:02:30 UTC


README

Runs PHP controller actions for HTTP requests and presents their results as JSON.

Русский · Architecture · MIT

Getting started

Requires PHP 8.4 or newer. Install version 0.1.0 from Packagist.

composer require denetorus/galaxy-application-rest-api:0.1.0

From the source checkout, install dependencies and run

composer install
php -S 127.0.0.1:8080 examples/index.php
# In another terminal / В другом терминале
curl http://127.0.0.1:8080/hello

Complete example examples/index.php.

Put controllers in App\Controller\RestApi and configure that namespace in Composer. A GET request to /hello invokes HelloController::actionDefault(). A second path segment selects the action. Override getAllowedHttpMethods() to allow other verbs. A JSON body is available as $input['json']. Missing controllers and actions return 404, a method mismatch returns 405 with Allow, and malformed JSON returns 400. Each action returns GResult. JsonPresenter emits the response. The application can set status and headers explicitly.

Reading a JSON request

For a POST action, return ['POST'] from getAllowedHttpMethods() for that action. Send an object with the JSON content type.

curl -X POST -H 'Content-Type: application/json' -d '{"name":"Ada"}' http://127.0.0.1:8080/hello

The action reads the decoded payload from $input['json']. Use GApp::createHttpErrorResult(1000, 'Name is required.', 422) to return a validation error with a business code and an explicit HTTP status. The bundled GET example returns 405 for this POST until you enable it.