How to use PSR HTTP standards to upgrade your code

This page summarizes the projects mentioned and recommended in the original post on

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern API for authentication & user identity.
  • Onboard AI - ChatGPT with full context of any GitHub repo.
  • catfacts-example

    A short example on how to use PSR HTTP standards for writing PHP Packages

    If you want to check out this code in its entirely you can head to this repo. It's in a useable state, but the API does not contain a lot of facts.

  • http-message

    The purpose of this PSR is to provide a set of common interfaces for HTTP messages as described in RFC 7230 and RFC 7231

    PSR-7, the standard for requests and responses

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • cat-facts

    Daily cat facts! 🐱

    declare(strict_types=1); namespace Rocksheep\CatFacts; use Exception; use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; use JsonException; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; class HttpClient { private ClientInterface $client; private RequestFactoryInterface $requestFactory; protected string $baseUrl = ''; public function __construct( ?ClientInterface $client = null, ?RequestFactoryInterface $requestFactory = null ) { $this->client = $client ?: Psr18ClientDiscovery::find(); $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory(); } /** * @throws JsonException * @throws Exception */ public function sendRequest(string $method, string $uri): array { $request = $this->requestFactory->createRequest($method, sprintf('%s/%s', $this->baseUrl, ltrim($uri, '/'))); try { $response = $this->client->sendRequest($request); } catch (ClientExceptionInterface $e) { throw new Exception('Oh well'); } if ($response->getStatusCode() >= 400) { throw new Exception('Too bad'); } $responseBody = (string) $response->getBody(); return json_decode($responseBody, false, 512, JSON_THROW_ON_ERROR); } }

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts