2017 © Pedro Peláez
 

library http

A shrimp of an HTTP utility library

image

caridea/http

A shrimp of an HTTP utility library

  • Sunday, January 14, 2018
  • by doublecompile
  • Repository
  • 1 Watchers
  • 0 Stars
  • 803 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

caridea-http

Caridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework., (*1)

, (*2)

This is its HTTP component. It includes small utilities for working with PSR-7 HTTP requests and responses, including:, (*3)

  • An implementation of RFC 7807, "Problem Details for HTTP APIs".
  • A utility to parse common pagination parameters from the request
  • A utility to correctly parse query strings with multiple parameters having the same name
  • A utility to determine a client's preferred accepted MIME type

Packagist Build Status Scrutinizer Code Quality Code Coverage Documentation Status, (*4)

Installation

You can install this library using Composer:, (*5)

$ composer require caridea/http
  • The master branch (version 3.x) of this project requires PHP 7.1 and depends on psr/http-message.
  • Version 2.x of this project requires PHP 7.0 and depends on psr/http-message.
  • Version 1.x of this project requires PHP 5.5 and depends on psr/http-message.

Compliance

Releases of this library will conform to Semantic Versioning., (*6)

Our code is intended to comply with PSR-1, PSR-2, and PSR-4. If you find any issues related to standards compliance, please send a pull request!, (*7)

Documentation

Examples

Just a few quick examples., (*8)

Problem Details

We included an implementation of RFC 7807 that you can serialize to JSON or append to a PSR-7 HTTP Response., (*9)

use Caridea\Http\ProblemDetails;
use Zend\Diactoros\Uri;

$problem = new ProblemDetails(
    new Uri('http://example.com/problem/oops'),  // type
    'A weird thing happened',                    // title
    500,                                         // status
    'It looks like the server has goofed again', // detail
    new Uri('http://example.com/problems/1f9a'), // instance
    [                                            // extensions
        'server' => 'workerbee01.example.com',
        'auth' => 'foobar'
    ]
);
echo json_encode($problem);

Pagination Factory

use Zend\Diactoros\ServerRequestFactory;

$request = ServerRequestFactory::fromGlobals(
    $_SERVER,
    \Caridea\Http\QueryParams::getFromServer(), // instead of $_GET
);

$factory = new \Caridea\Http\PaginationFactory();

// say the Query was ?count=25&startIndex=1&sort=%2Bfoo&sort-bar
// or maybe          ?count=25&start=0&sort=%2Bfoo,-bar
// or one of many other formats for this type of pagination settingns
$pagination = $factory->create($request, 'sort');
$pagination->getMax();    // 25
$pagination->getOffset(); // 0
$pagination->getOrder();  // ['foo' => true, 'bar' => false]

Accept Types

// say the HTTP_ACCEPT field is text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
$types = new \Caridea\Http\AcceptTypes($_SERVER);
$types->preferred(['application/xml', 'application/json']); // returns application/xml

Helper Traits

Two traits are now available, JsonHelper and MessageHelper. These can be used by controller classes or dispatcher middleware., (*10)

Third-Party

The traits JsonHelper and MessageHelper (as well as their unit tests) were ported to PHP from the Labrys library under a compatible Apache 2.0 license., (*11)

The Versions

14/01 2018

dev-master

9999999-dev http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

mime http problem details rfc7807 rfc 7807

14/01 2018

3.0.0

3.0.0.0 http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

mime http problem details rfc7807 rfc 7807

23/03 2017

2.2.0

2.2.0.0 http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details rfc7807 rfc 7807

23/03 2017

2.2.x-dev

2.2.9999999.9999999-dev http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details rfc7807 rfc 7807

19/09 2016

2.1.0

2.1.0.0 http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details rfc7807 rfc 7807

19/09 2016

2.1.x-dev

2.1.9999999.9999999-dev http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details rfc7807 rfc 7807

22/03 2016

2.0.0

2.0.0.0 http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details

22/03 2016

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details

22/03 2016

1.x-dev

1.9999999.9999999.9999999-dev http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details

22/03 2016

1.0.0

1.0.0.0 http://github.com/libreworks/caridea-http

A shrimp of an HTTP utility library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

http problem details