Download the PHP package tiny-blocks/http without Composer
On this page you can find all versions of the php package tiny-blocks/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tiny-blocks/http
More information about tiny-blocks/http
Files in tiny-blocks/http
Package http
Short Description Common implementations for HTTP protocol.
License MIT
Homepage https://github.com/tiny-blocks/http
Informations about the package http
Http
- Overview
- Installation
- How to use
- Using the status code
- Creating a response
- License
- Contributing
Overview
Common implementations for HTTP protocol. The library exposes concrete implementations that follow the PSR standards, specifically designed to operate with PSR-7 and PSR-15, providing solutions for building HTTP responses, requests, and other HTTP-related components.
Installation
How to use
The library exposes interfaces like Headers
and concrete implementations like Response
, ContentType
, and others,
which facilitate construction.
Using the status code
The library exposes a concrete implementation through the Code
enum. You can retrieve the status codes, their
corresponding messages, and check for various status code ranges using the methods provided.
-
Get message: Returns the HTTP status message associated with the enum's code.
-
Check if the code is valid: Determines if the given code is a valid HTTP status code represented by the enum.
-
Check if the code is an error: Determines if the given code is in the error range (4xx or 5xx).
- Check if the code is a success: Determines if the given code is in the success range (2xx).
Creating a response
The library provides an easy and flexible way to create HTTP responses, allowing you to specify the status code,
headers, and body. You can use the Response
class to generate responses, and the result will always be a
ResponseInterface
from the PSR, ensuring compatibility with any framework that adheres
to the PSR-7 standard.
-
Creating a response with a body: To create an HTTP response, you can pass any type of data as the body. Optionally, you can also specify one or more headers. If no headers are provided, the response will default to
application/json
content type. - Creating a response with a body and custom headers: You can also add custom headers to the response. For instance, if you want to specify a custom content type or any other header, you can pass the headers as additional arguments.
License
Http is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.
All versions of http with dependencies
psr/http-message Version ^1.1
tiny-blocks/mapper Version ^1
ext-mbstring Version *