Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lmc-eu/http-constants
The missing PHP constants for HTTP header fields
https://github.com/lmc-eu/http-constants
constants guzzle http php
Last synced: about 7 hours ago
JSON representation
The missing PHP constants for HTTP header fields
- Host: GitHub
- URL: https://github.com/lmc-eu/http-constants
- Owner: lmc-eu
- License: mit
- Created: 2017-07-24T12:46:53.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T14:00:38.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T20:49:25.785Z (4 days ago)
- Topics: constants, guzzle, http, php
- Language: PHP
- Homepage:
- Size: 36.1 KB
- Stars: 25
- Watchers: 7
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# HTTP Header Fields Constants for PHP
[![Latest Stable Version](https://img.shields.io/packagist/v/lmc/http-constants.svg?style=flat-square)](https://packagist.org/packages/lmc/http-constants)
[![GitHub Actions Build Status](https://img.shields.io/github/actions/workflow/status/lmc-eu/http-constants/tests.yaml?style=flat-square)](https://github.com/lmc-eu/http-constants/actions)
[![Total Downloads](https://img.shields.io/packagist/dt/lmc/http-constants.svg?style=flat-square)](https://packagist.org/packages/lmc/http-constants)The missing PHP constants definition for header fields of your HTTP requests and responses.
Stop repeating string identifiers and placing typos of HTTP headers in your code!
Could be used when interacting with headers using [pure PHP], [Guzzle], [Symfony HttpFoundation], [Zend HTTP], [Zend Diactoros] etc.
Contains all ~200 constants for headers defined in [IANA list] (both Permanent and Provisional) and some common non-standard headers based on [Wikipedia list].
## Install
```sh
$ composer require lmc/http-constants
```Note you will need to have [Composer](https://getcomposer.org/) installed to do this.
## Usage
```php
request(
'GET',
'https://api.foo/bar',
['headers' => [Header::ACCEPT_ENCODING => 'gzip']]
);echo $response->getHeaderLine(Header::CONTENT_TYPE);
}public function exampleWithSymfonyHttpFoundation()
{
$response = new \Symfony\Component\HttpFoundation\Response();
$response->headers->set(Header::ACCESS_CONTROL_ALLOW_ORIGIN, 'www.jobs.cz');
}public function exampleWithPurePhp()
{
header(Header::CONTENT_TYPE . ': application/pdf');
header(Header::CACHE_CONTROL . ': no-cache, must-revalidate');
}
}```
## Changelog
For latest changes see [CHANGELOG.md](CHANGELOG.md) file. We follow [Semantic Versioning](http://semver.org/).## License
The library is open source software licensed under the [MIT license](LICENCE.md).[pure PHP]: https://www.php.net/manual/en/function.header.php
[Guzzle]: https://github.com/guzzle/guzzle
[Symfony HttpFoundation]: https://symfony.com/doc/current/components/http_foundation.html
[Zend HTTP]: https://zendframework.github.io/zend-http/
[Zend Diactoros]: https://zendframework.github.io/zend-diactoros/
[IANA list]: https://www.iana.org/assignments/message-headers/message-headers.xml
[Wikipedia list]: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields