Skip to content

Commit 5dd9020

Browse files
Nyholmdbu
authored andcommitted
Improved docs for library developers (#126)
Improved docs for library developers
1 parent 0a08c07 commit 5dd9020

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

_static/highlight.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ table.highlighttable td div.linenodiv {
5353
text-align: right;
5454
width: 38px;
5555
}
56+
57+
div.highlight-json pre span.nt {
58+
color: cornsilk;
59+
}

httplug/library-developers.rst

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ If you’re developing a library or framework that performs HTTP requests, you
55
should not be dependent on concrete HTTP client libraries (such as Guzzle).
66
Instead, you should only make sure that *some* HTTP client is available. It is
77
then up to your users to decide which HTTP client they want to include in their
8-
projects.
8+
projects. This complies with the `dependency inversion principle`_.
99

1010
Manage dependencies
1111
-------------------
@@ -38,14 +38,12 @@ to include the Socket client:
3838
}
3939
}
4040
41-
Standalone installation
42-
-----------------------
41+
Testing you library
42+
-------------------
4343

44-
This is sufficient for your library’s users. For the library’s developers,
45-
however, it’s best if some specific client is installed when they run
46-
``composer install`` in the library’s directory. So specify any concrete client
47-
in the ``require-dev`` section in your library’s ``composer.json``. In this
48-
example, we chose the Guzzle 6 adapter:
44+
When you install your library on a CI-server (like Travis) you need to include a client. So specify any concrete client
45+
in the ``require-dev`` section in your library’s ``composer.json``. You could use any client but the
46+
:doc:`/clients/mock-client` will make it easier to write good tests.
4947

5048
.. code-block:: json
5149
@@ -55,19 +53,23 @@ example, we chose the Guzzle 6 adapter:
5553
"php-http/client-implementation": "^1.0"
5654
},
5755
"require-dev": {
58-
"php-http/guzzle6-adapter": "^1.0"
56+
"php-http/mock-client": "^0.3"
5957
}
6058
}
6159
62-
For extra convenience, you can use :doc:`/discovery` to free your users from
63-
having to instantiate the client.
60+
6461
6562
Messages
6663
--------
6764

68-
When you construct HTTP message objects in your library, you should not depend
69-
on a concrete PSR-7 message implementation. Instead, use the
70-
:ref:`PHP-HTTP message factory <message-factory>`.
65+
When you construct HTTP message objects in your library, you should not depend on a concrete PSR-7 message
66+
implementation. Instead, use the :ref:`PHP-HTTP message factory <message-factory>`.
67+
68+
Discovery
69+
---------
70+
71+
To make it as convenient as possible for your users you should use the :doc:`/discovery` component. It will help you
72+
find factories to create ``Request``, ``Streams`` etc. That component is light weight and has no hard dependencies.
7173

7274
Plugins
7375
-------
@@ -81,3 +83,29 @@ User documentation
8183

8284
To explain to your users that they need to install a concrete HTTP client,
8385
you can point them to :doc:`users`.
86+
87+
88+
You final ``composer.json``
89+
---------------------------
90+
91+
Putting it all together your final ``composer.json`` is much likely to look similar to this:
92+
93+
.. code-block:: json
94+
95+
{
96+
"name": "you/and-your-awesome-library",
97+
"require": {
98+
"psr/http-message": "^1.0",
99+
"php-http/client-implementation": "^1.0",
100+
"php-http/httplug": "^1.0",
101+
"php-http/message-factory": "^1.0",
102+
"php-http/discovery": "^1.0"
103+
},
104+
"require-dev": {
105+
"php-http/mock-client": "^0.3",
106+
"php-http/message": "^1.0",
107+
"guzzlehttp/psr7": "^1.0"
108+
}
109+
}
110+
111+
.. _`dependency inversion principle`: https://en.wikipedia.org/wiki/Dependency_inversion_principle

0 commit comments

Comments
 (0)