Skip to content

Commit

Permalink
Add other services doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Apr 15, 2018
1 parent 0aec286 commit 1d42ae8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/advanced/other-services.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Serving TwirPHP with other services
===================================

In some cases you might want to serve not just one, but multiple services from one application.
The generated code contains a simple server implementation which lets you mux different services.

.. code-block:: php
$server = new \Twitch\Twirp\Example\Server();
// register services
$server->registerServer(
\Twitch\Twirp\Example\HaberdasherServer::PATH_PREFIX,
new \Twitch\Twirp\Example\HaberdasherServer(
new \Twirphp\Example\Haberdasher()
)
);
Both the server and service server implement the same ``RequestHandler`` interface, so you can use the same code
as in the :ref:`run-server` usage example:

.. code-block:: php
// ...
$response = $server->handle($request);
2 changes: 1 addition & 1 deletion docs/getting-started/best-practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are three types of "resources" to consider in case of a PHP projects using

Following common PHP packaging practice the recommended folder structure is:

.. code-block::
.. code-block:: text
/generated
/<namespace>
Expand Down
2 changes: 2 additions & 0 deletions docs/getting-started/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Now that everything is in place, it's time to implement the server implementing
}
.. _run-server:

Run the server
--------------

Expand Down
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ resources published by the Twirp developers themselves:
getting-started/usage
getting-started/best-practices

.. toctree::
:hidden:
:caption: Beyond the basics

advanced/other-services


.. _Twirp: https://twitchtv.github.io/twirp/
.. _protobuf: https://developers.google.com/protocol-buffers/
1 change: 1 addition & 0 deletions docs/spelling_word_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Quickstart
quickstart
metapackage
entrypoint
proto

0 comments on commit 1d42ae8

Please sign in to comment.