Contributte Http
# Content
- Setup
- Curl - simple http client (CurlExtension)
- SAPI - fake request (CliRequestExtension)
- BasicAuth - simple basic authentication
- Useful classes
# Setup
composer require contributte/http
1
# Curl
There is a prepared simple cURL client in this package.
You have to register it at first.
extensions:
curl: Contributte\Http\DI\CurlExtension
1
2
2
Extension registers Contributte\Http\Curl\CurlClient
(opens new window) as a service.
# SAPI
Every modern PHP application needs sometimes to run a few console commands. Let's say sending newsletter campaigns. There is
a tiny problem, there is no request/URL in console/SAPI (Server API) mode. Don't worry, just use our fake request -
SapiRequestExtension
.
extensions:
sapi: Contributte\Http\DI\SapiRequestExtension
1
2
2
List of all options:
sapi:
url: https://contributte.org
# other params
query: null
post: null
files: null
cookies: null
headers: null
method: null
remoteAddress: null
remoteHost: null
rawBodyCallback: null
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# Basic Authentication
extensions:
auth: Contributte\Http\DI\BasicAuthExtension
1
2
2
You have to enable
this extension by yourself. It's disabled by default.
auth:
enabled: true/false
title: My security zone
users:
username1:
password: password1
unsecured: true
username2:
password: $2y$10$p.U5q.BuQp02srggig.VDOqj5m7pE1rCwKavVQ3S2TrqWlkqu3qlC
unsecured: false # secured by default
username3:
password: $2y$10$bgievYVQMzsRn5Ysup.NKOVUk66aitAniAmts2EJAa91eqkAhohvC
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# Useful classes
# Url
Few methods added:
# $url->appendPath($path)
use Contributte\Http\Url;
$url = new Url('https://github.com');
$url->appendPath('foo');
# https://github.com/foo
$url->appendPath('bar');
# https://github.com/foobar
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9