Download the PHP package parable-php/http without Composer
On this page you can find all versions of the php package parable-php/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download parable-php/http
More information about parable-php/http
Files in parable-php/http
Package http
Short Description Parable HTTP is a straight-forward Request/Response library
License MIT
Homepage https://github.com/parable-php/http
Informations about the package http
Parable Http
Parable Http is a minimalist Http library used to receive requests and send responses. It is not a full implementation, offering just-enough functionality.
Install
Php 8.0+ and composer are required.
Usage
To create a Request
object automatically from the server variables, use:
To create a Request
from scratch, use:
To set up a minimal response you want to send to the client:
And to send it, use the Dispatcher
:
This will send a response with stat
us code 200
, with the body set as passed to the Response
upon creation.
API
Request
getMethod(): string
- returns GET, POST, etc.getUri(): Uri
- return aUri
object representing the uri being requestedgetRequestUri(): ?string
- the path of theUri
getProtocol(): string
- the protocol used (i.e.HTTP/1.1
)getProtocolVersion(): string
- the version part of the protocol (i.e.1.1
)getBody(): ?string
- the body of the request, if anygetUser(): ?string
- the username from the urigetPass(): ?string
- the password from the uriisHttps(): bool
- whether the request was made over https. This represents a 'best guess' based on multiple checksisMethod(string $method): bool
- check whether the method matches$method
From the HasHeaders
trait:
getHeader(string $header): ?string
- get a single header by string,null
if non-existinggetHeaders(): string[]
- get all headers
Response
getBody(): ?string
- the body to be sentsetBody(string $body): void
- set the body as a stringprependBody(string $content): void
- prepend the value to the bodyappendBody(string $content): void
- append the value to the bodygetContentType(): string
- the content type (i.e.text/html
,application/json
)setContentType(string $contentType): void
- set the content typegetProtocol(): string
- the protocol to be sent with (i.e.HTTP/1.1
)getProtocolVersion(): string
- the protocol version (i.e.1.1
)setProtocol(string $protocol): void
- set the protocolsetHeaders(array $headers): void
- set multiple headers, resettingaddHeaders(array $headers): void
- add multiple headersaddHeader(string $header, string $value): void
- add single header
From the HasHeaders
trait:
getHeader(string $header): ?string
- get a single header by string,null
if non-existinggetHeaders(): string[]
- get all headers
From the HasStatusCode
trait:
getStatusCode(): int
- the status code to be sent (i.e.200
)getStatusCodeText(): ?string
- the status code text to be sent (i.e.OK
)setStatusCode(int $statusCode): void
- set the status code
Dispatcher
dispatch(Response $response): void
- dispatch a Response, sending all its content as setdispatchAndTerminate(Response $response, int $exitCode = 0): void
- dispatch a Response and terminate, i.e., ending program flow immediately afterwards
Contributing
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at devvoh.com.
License
All Parable components are open-source software, licensed under the MIT license.