terrazza/http

Terrazza Component Http

dev-main 2022-05-12 21:30 UTC

This package is auto-updated.

Last update: 2024-04-13 01:31:27 UTC


README

This component is for any interaction with/from Http

  1. Object/Classes
    1. Client
    2. Message
    3. Request
    4. Response
    5. Stream
  2. Install
  3. Requirements

Object/Classes

Client

HttpClient

common psr interface implementation.

Message

Uri

common psr interface implementation.

HttpMessageAdapter

..description missing

HttpMessageHelper

..description missing

Request

implementations are really close to the common psr interfaces.
the differences are explained.

HttpClientRequest (RequestInterface)

  • public function withContentType(string $contentType)
  • public function withContent(string $contentType, $body)
  • public function getPathParam(string $routeUri, string $argumentName)
  • public function getQueryParam(string $argumentName)
  • public function withQueryParams(array $query)
    request->uri->query will be also updated
  • public function withUploadedFiles(array $uploadFiles)
  • public function withUploadedFile(string $formDataName, UploadedFileInterface $uploadedFile)

HttpRequestFactory

HttpRequestFactory covers some HttpRequest methods.

method: getServerRequest() : IHttpServerRequest

HttpRequestHelper (Trait)

trait for common methods used in HttpRequest and HttpServerRequest.

HttpRequestMiddleware

HttpRequestMiddleware provides a middleware implementation.

HttpServerRequest (ServerRequestInterface)

method: getServerParam(string $paramKey)
method: getCookieParam(string $paramKey)
method: getPathParam(string $routeUri, string $argumentName)
method: getQueryParam(string $argumentName)
method: withQueryParams(array $queryParams)

request->uri->query will be also updated

method: isValidBody()

validate Content-Type against ->body

HttpServerRequest

..description missing

Response

all implementations are really close to psr interfaces. only the differences explained.

HttpResponse (ResponseInterface)

HttpResponse implements the common psr interface.

HttpResponseFactory (ResponseFactoryInterface)

HttpResponseFactory implements the psr interface and

method: createJsonResponse(int $responseCode, $content)

Stream

HttpStream

HttpStream implements the psr interface and

  • __constructor
    is public and the class can be used directly
method: getContents(bool $rewindAfterReading=false)

rewindAfterReading set stream->seek(0) to reuse the content

method: setMediaType(string $mediaType)

set mime_type. StreamFactory->createStreamFromFile will do this automatically

method: getMediaType()
method: setFileName(string $fileName)

set fileName. StreamFactory->createStreamFromFile will do this automatically

method: getFileName()

HttpStreamFactory

HttpStreamFactory create the HttpStream directly without using any static functions. That allows us to inject the factory.

method: createStreamFromFile

set, in case of a touchable file, mimeType and fileName to the HttpStream Object (IHttpStream).

UploadFile

  • private function setStreamOrFile($streamOrFile)
    streamOrFile
    . is a touchable file
    . or an instanceof IHttpStream
    ClientMediaType and ClientFilename are set, if present.

Install

Install via composer

composer require terrazza/component-http

Requirements

php version

  • >= 7.4

php extension

  • ext-curl
  • ext-json
  • ext-fileinfo