phphttpstructure

Best practices for structuring a PHP HTTP client library


I'm currently designing a PHP HTTP library and I'm trying to decide between two possible directory structures. Which one would be considered better practice, and why?

Structure A

+ httpLib/
|   . Index.php / Factory
|   . API.php
|   . _Exception.php
|   + Response/
|   |   . Interface.php
|   |   . ...
|   + Request/
|   |   . Interface.php
|   |   . ...

Structure B

+ httpLib/
|   . Response.php
|   . Request.php
|   . API.php
|   . _Exception.php
|   + Client/
|   |   . Interface.php
|   |   . Socket.php
|   |   . Stream.php
|   |   . cURL.php
...

Thanks in advance!


Solution

  • The first structure is the best.

    With it you can better separate the requests and responses.

    The structures of the requests and responses are well defined and not in a single class