6

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 PHP PSR7. I am trying to figure out why it has both the RequestInterface and the ServerRequestInterface. I can't seam to fine anything about it anywhere and I can't see the reason for why these two are not just merged into one interface.

Anon Mou
  • 73
  • 4

2 Answers2

5

I agree that it is not clear what they mean by "server-side requests". It is known that HTTP requests are sent by clients (browsers, bots, REST API users etc.), and received by servers, after all. However, the word "server" may refer to different things in different contexts.

An HTTP request is received by an HTTP server such as Apache, Nginx, and Microsoft IIS. The servers provide Server Application Programming Interface (SAPI) which particularly allows to postprocess information parsed by the web servers.

The PHP engine (Zend) interacts with different environments by means of its SAPI (Server API) module. The module consists of a number of submodules: CLI (Command Line Interface), CGI (Common Gateway Interface), Apache, FPM (FastCGI Process Manager), and others. Each have their own ideas about contents of the PHP superglobals (example).

The raw HTTP requests are parsed by a Web server. PHP requests the parsed data from the Web server through SAPI for further processing, then passes it to us in the form of superglobals, particularly.

RequestInterface thus represents the first simple HTTP request which doesn't classify its headers, or parts of the message body into cookies, upload data, GET-, or POST-variables etc. as it is indirectly mentioned in the official documentation:

The RequestInterface and ResponseInterface have essentially 1:1 correlations with the request and response messages described in RFC 7230. They provide interfaces for implementing value objects that correspond to the specific HTTP message types they model.

It simply provides interface for common request parameters such as URI, scheme, query, and port, for instance.

And ServerRequestInterface represents the parsed version of the simple representation of HTTP message (request). It introduces access to logically classified parts of the message, the parts generated server-side: uploaded files, cookies, server parameters, and others.

I suggest thinking of RequestInterface as HTTP request as it came from the client. And ServerRequestInterface as already not quite client's request =), i.e. version of original request modified by the server (SAPI).

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
  • Thank you that makes much more sense. What got me turned most around was the fact that they refer to it as Server-Side and Client-Side Requests in the documentation of PSR7. Server-side sounds like a server making a request and Client-side as the opposite. Raw request vs. SAPI manipulated request makes more sense. – Anon Mou Oct 13 '16 at 21:41
1

cant give a better answer than:

RequestInterface provides the general representation of an HTTP request message. However, server-side requests need additional treatment, due to the nature of the server-side environment. Server-side processing needs to take into account Common Gateway Interface (CGI), and, more specifically, PHP's abstraction and extension of CGI via its Server APIs (SAPI). PHP has provided simplification around input marshaling via superglobals such as:

..

ServerRequestInterface extends RequestInterface to provide an abstraction around these various superglobals. This practice helps reduce coupling to the superglobals by consumers, and encourages and promotes the ability to test request consumers.

http://www.php-fig.org/psr/psr-7/

  • That explains that Server Requests needs additional treatment, but not what a Server Request is. What/Who makes such a request? Server Request vs Client Request, that's what I am after. – Anon Mou Oct 13 '16 at 02:23
  • server request = HTTP request. is that clear? the server in this case is an http server –  Oct 13 '16 at 02:35
  • Okay, so a Server Request is just the normal requests made by clients to servers. That makes much more sense, so I am guessing that the `RequestInterface` is for things like CLI Requests and similar? – Anon Mou Oct 13 '16 at 02:40
  • RequestInterface covers *all* requests from a client to a server. and ServerRequestInterface deals with the particulars of the supergloblas –  Oct 13 '16 at 02:45