A form parser for Amp's HTTP parser.

Fund package maintenance!

Installs: 53 402

Dependents: 10

Suggesters: 0

Security: 0

Stars: 14

Watchers: 8

Forks: 5

Open Issues: 1


v2.0.0-beta.3 2023-04-22 15:36 UTC

This package is auto-updated.

Last update: 2023-05-27 03:29:52 UTC


This package is an add-on to amphp/http-server, which allows parsing request bodies as forms in either x-www-form-urlencoded or multipart/form-data format.


This package can be installed as a Composer dependency.

composer require amphp/http-server-form-parser


Basic usage works by calling parseForm($request), which will buffer the request body and parse it.


use Amp\Http\Server\FormParser;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Status;

new CallableRequestHandler(function (Request $request) {
    /** @var FormParser\Form $form */
    $form = yield FormParser\parseForm($request);

    return new Response(Status::OK, [
        "content-type" => "text/plain; charset=utf-8"
    ], $form->getValue("text") ?? "Hello, World!");

There's also an advanced streaming parser included, which can be used to stream uploaded files to disk or other locations.