amphp/http-server-form-parser

An HTTP server plugin that simplifies form data handling. Effortlessly parse incoming form submissions and extracting its data.

Package info

github.com/amphp/http-server-form-parser

Homepage

Language:HTML

pkg:composer/amphp/http-server-form-parser

Fund package maintenance!

amphp

Statistics

Installs: 107 020

Dependents: 16

Suggesters: 0

Stars: 18

Open Issues: 1

v2.0.0 2023-08-25 02:52 UTC

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 6f160914a1cd9aaa104b589c0c590613600bfa70

  • Daniel Lowrey <rdlowrey.woop@php.net>
  • Bob Weinand
  • Niklas Keller <me.woop@kelunik.com>
  • Aaron Piotrowski <aaron.woop@trowski.com>

httpformasyncnon-blockingampamphprevolt

This package is auto-updated.

Last update: 2026-06-25 09:14:36 UTC


README

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.

Installation

This package can be installed as a Composer dependency.

composer require amphp/http-server-form-parser

Usage

Basic usage works by calling Form::fromRequest($request), which will buffer the request body and parse it. This method may be called multiple times, so both a middleware and request handler may access the form body.

use Amp\Http\Server\FormParser\Form;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Status;

$requestHandler = new ClosureRequestHandler(function (Request $request) {
 $form = Form::fromRequest($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, StreamingFormParser, which can be used to stream uploaded files to disk or other locations.