Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amphp/http-server-form-parser
An HTTP server plugin that simplifies form data handling. Effortlessly parse incoming form submissions and extracting its data.
https://github.com/amphp/http-server-form-parser
amphp form forms html http http-server multipart-formdata parser php x-www-form-urlencoded
Last synced: 4 days ago
JSON representation
An HTTP server plugin that simplifies form data handling. Effortlessly parse incoming form submissions and extracting its data.
- Host: GitHub
- URL: https://github.com/amphp/http-server-form-parser
- Owner: amphp
- License: mit
- Created: 2018-03-14T21:14:40.000Z (over 6 years ago)
- Default Branch: 2.x
- Last Pushed: 2023-08-25T03:00:49.000Z (about 1 year ago)
- Last Synced: 2024-09-19T05:44:50.561Z (about 2 months ago)
- Topics: amphp, form, forms, html, http, http-server, multipart-formdata, parser, php, x-www-form-urlencoded
- Language: HTML
- Homepage: https://amphp.org/http-server-form-parser
- Size: 134 KB
- Stars: 18
- Watchers: 8
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-server-form-parser
This package is an add-on to [`amphp/http-server`](https://github.com/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](https://getcomposer.org/) dependency.
```bash
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](https://github.com/amphp/http-server#middleware) and [request handler](https://github.com/amphp/http-server#requesthandler) may access the form body.
```php
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.