Questions tagged [psr-7]

PSR-7 is the FIG standard for HTTP messages in PHP. It provides abstractions of HTTP messages and their components and defines a consistent set of interfaces to work with them.

The purpose of PSR-7 is to provide PHP with a set of common interfaces for HTTP messages as described in RFC 7230 and RFC 7231, and URIs as described in RFC 3986 (in the context of HTTP messages).

All HTTP messages consist of the HTTP protocol version being used, headers, and a message body. A Request builds on the message to include the HTTP method used to make the request, and the URI to which the request is made. A Response includes the HTTP status code and reason phrase.

In PHP, HTTP messages are used in two contexts:

  • To send an HTTP request, via the ext/curl extension, PHP's native stream layer, etc., and process the received HTTP response. In other words, HTTP messages are used when using PHP as an HTTP client.
  • To process an incoming HTTP request to the server, and return an HTTP response to the client making the request. PHP can use HTTP messages when used as a server-side application to fulfil HTTP requests.
91 questions
43
votes
6 answers

How to read the response effective URL in Guzzle ~6.0

I've been searching for about 2 hours and I can't figure it out how to read the final response uri. In previous versions of PHP Guzzle you just call $response->getEffectiveUrl() and you get it. I expected to have something similar in the new version…
joserobleda
  • 688
  • 1
  • 8
  • 12
38
votes
4 answers

Slim 3 - how to get all get/ put/ post variables?

How I can get all get/ put/ post variables like in Slim 2 for Slim 3? Slim 2, $allGetVars = $app->request->get(); $allPutVars = $app->request->put(); $allPostVars = $app->request->post(); How can I do that in Slim 3? And, for example,…
laukok
  • 47,545
  • 146
  • 388
  • 689
12
votes
3 answers

Create a stream from a resource

I know that I can create a PHP stream from a filename (a real one, or an URL), by using the fopen function: $stream = fopen('php://temp', 'r'); The resulting stream ($stream) is then a resource of type "stream", created from the URL php://temp. But…
dakis
  • 225
  • 1
  • 6
  • 32
12
votes
1 answer

Psr7 Http Message, why immutable?

I am looking at the PSR-7 interfaces and thinking of a way on how to implement them. I've also been reading this blog post. Apparently the objects that implement the PSR-7 interfaces must be immutable. So if I implement the withProtocolVersion…
Vivendi
  • 16,485
  • 22
  • 93
  • 175
9
votes
2 answers

Guzzle not sending PSR-7 POST body correctly

It is either not being sent, or not being received correctly. Using curl direct from the command line (using the -d option) or from PHP (using CURLOPT_POSTFIELDS) does work. I start with a PSR-7 request: $request = GuzzleHttp\Psr7\Request('POST',…
Jason
  • 2,506
  • 4
  • 31
  • 43
6
votes
3 answers

Object of class GuzzleHttp\Psr7\Request could not be converted to string

I've got an issue for laravel 5.4 when I trying to using guzzleHttp. here is my code. use GuzzleHttp\Client; $url = 'http://example.com'; $client = new Client(); $parameter = ['query' => ['name' => 'xxx', 'address' => 'yyy'], 'headers' => […
php dev
  • 71
  • 1
  • 1
  • 4
6
votes
4 answers

How to access all routes from Slim 3 php framework?

I am trying to build a dynamic drop-down menu from routes defined in Slim framework and here is my question - is there a way to access all defined static routes from some kind of array? For instance, if I define my routes like this: // Index page:…
Vladimir Jovanović
  • 2,100
  • 18
  • 23
6
votes
2 answers

Meaning of Server-Side Request

I was wondering if someone could explain to me the meaning of a Server-Side Request. It might just be the terminology I don't quite get. To me it sounds like a request from the server to the client, but I don't think that's it. It's regarding the…
Anon Mou
  • 73
  • 4
6
votes
1 answer

Should I use psr-7 for laravel requests / responses?

i have been using slim 3 and finally got my head around psr-7. Now working with laravel i see that out of the box, psr-7 is not supported. Now... is there a strong reason to follow psr-7 or the laravel request styles? personal preference for…
Toskan
  • 11,184
  • 12
  • 75
  • 144
5
votes
1 answer

How to use PSR-7 responses?

The majority of responses in my application are either views or JSON. I can't figure out how to put them in objects that implement ResponseInterface in PSR-7. Here is what I currently do: // Views header('Content-Type: text/html;…
rink.attendant.6
  • 36,468
  • 57
  • 89
  • 143
5
votes
2 answers

Slim 3 - How to add 404 Template?

In Slim 2, I can over write the default 404 page easily, // @ref: http://help.slimframework.com/discussions/problems/4400-templatespath-doesnt-change $app->notFound(function () use ($app) { $view = $app->view(); …
laukok
  • 47,545
  • 146
  • 388
  • 689
4
votes
2 answers

Where to put new objects generated by middleware?

PSR-7 is going to be standardized soon (I believe). That's got me thinking about middlewares, such as used by Phly, StackPHP, and ConnectJS. The way ConnectJS works is that it modifies the request object when a middleware needs to add something. For…
mpen
  • 237,624
  • 230
  • 766
  • 1,119
3
votes
1 answer

PSR-7: getParsedBody() vs getBody()

Scenario 1 sending x-www-form-urlencoded data POST /path HTTP/1.1 Content-Type: application/x-www-form-urlencoded foo=bar Running print_r($request->getParsedBody()); returns fine: Array ( [foo] => bar ) Running…
IMB
  • 12,083
  • 16
  • 59
  • 118
3
votes
2 answers

Call to undefined method GuzzleHttp\Psr7\Response::isSuccessful()

So I have installed the Guzzle library version 6 according to TeamUp calendar documentation. However, when I try to run the code below I get Fatal error: Call to undefined method GuzzleHttp\Psr7\Response::isSuccessful() code:
bmm
  • 187
  • 1
  • 4
  • 17
3
votes
1 answer

Sf2 RedirectResponse not working

I am using the HttpFoundation component in my project without using the full Symfony2 framework. I try to make a RedirectResponse if some credentials are true and redirect the user (like stated in the documentation), but the return statement is not…
Ivan
  • 4,530
  • 11
  • 42
  • 69
1
2 3 4 5 6 7