md_doc_command_line_tool.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.17"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC Objective-C: gRPC command line tool</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">GRPC Objective-C
  25. &#160;<span id="projectnumber">1.36.1</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.17 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */</script>
  48. <div id="main-nav"></div>
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. </div><!-- top -->
  62. <div class="PageDoc"><div class="header">
  63. <div class="headertitle">
  64. <div class="title">gRPC command line tool </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><h1><a class="anchor" id="autotoc_md42"></a>
  68. Overview</h1>
  69. <p>This document describes the command line tool that comes with gRPC repository. It is desirable to have command line tools written in other languages roughly follow the same syntax and flags.</p>
  70. <p>At this point, the tool needs to be built from source, and it should be moved out to grpc-tools repository as a stand alone application once it is mature enough.</p>
  71. <h1><a class="anchor" id="autotoc_md43"></a>
  72. Core functionality</h1>
  73. <p>The command line tool can do the following things:</p>
  74. <ul>
  75. <li>Send unary rpc.</li>
  76. <li>Attach metadata and display received metadata.</li>
  77. <li>Handle common authentication to server.</li>
  78. <li>Infer request/response types from server reflection result.</li>
  79. <li>Find the request/response types from a given proto file.</li>
  80. <li>Read proto request in text form.</li>
  81. <li>Read request in wire form (for protobuf messages, this means serialized binary form).</li>
  82. <li>Display proto response in text form.</li>
  83. <li>Write response in wire form to a file.</li>
  84. </ul>
  85. <p>The command line tool should support the following things:</p>
  86. <ul>
  87. <li>List server services and methods through server reflection.</li>
  88. <li>Fine-grained auth control (such as, use this oauth token to talk to the server).</li>
  89. <li>Send streaming rpc.</li>
  90. </ul>
  91. <h1><a class="anchor" id="autotoc_md44"></a>
  92. Code location</h1>
  93. <p>To use the tool, you need to get the grpc repository and make sure your system has the prerequisites for building grpc from source, given in the ../BUILDING.md "installation
  94. instructions".</p>
  95. <p>In order to build the grpc command line tool from a fresh clone of the grpc repository, you need to run the following command to update submodules:</p>
  96. <div class="fragment"><div class="line">git submodule update --init</div>
  97. </div><!-- fragment --><p>Once the prerequisites are satisfied, you can build with cmake:</p>
  98. <div class="fragment"><div class="line">$ mkdir -p cmake/build</div>
  99. <div class="line">$ cd cmake/build</div>
  100. <div class="line">$ cmake -DgRPC_BUILD_TESTS=ON ../..</div>
  101. <div class="line">$ make grpc_cli</div>
  102. </div><!-- fragment --><p>The main file can be found at <a href="https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc">https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc</a></p>
  103. <h1><a class="anchor" id="autotoc_md45"></a>
  104. Prerequisites</h1>
  105. <p>Most <code>grpc_cli</code> commands need the server to support server reflection. See guides for <a href="https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md#enable-server-reflection">Java</a> , <a href="https://github.com/grpc/grpc/blob/master/doc/server_reflection_tutorial.md">C++</a> and <a href="https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md">Go</a></p>
  106. <p>Local proto files can be used as an alternative. See instructions <a href="#Call-a-remote-method">below</a>.</p>
  107. <h1><a class="anchor" id="autotoc_md46"></a>
  108. Usage</h1>
  109. <h2><a class="anchor" id="autotoc_md47"></a>
  110. List services</h2>
  111. <p><code>grpc_cli ls</code> command lists services and methods exposed at a given port</p>
  112. <ul>
  113. <li><p class="startli">List all the services exposed at a given port</p>
  114. <p class="startli">```sh $ grpc_cli ls localhost:50051 ```</p>
  115. <p class="startli">output:</p>
  116. <p class="startli">```none helloworld.Greeter grpc.reflection.v1alpha.ServerReflection ```</p>
  117. <p class="startli">The <code>localhost:50051</code> part indicates the server you are connecting to.</p>
  118. </li>
  119. <li><p class="startli">List one service with details</p>
  120. <p class="startli"><code>grpc_cli ls</code> command inspects a service given its full name (in the format of &lt;package&gt;.&lt;service&gt;). It can print information with a long listing format when <code>-l</code> flag is set. This flag can be used to get more details about a service.</p>
  121. <p class="startli">```sh $ grpc_cli ls localhost:50051 helloworld.Greeter -l ```</p>
  122. <p class="startli"><code>helloworld.Greeter</code> is full name of the service.</p>
  123. <p class="startli">output:</p>
  124. <p class="startli">```proto filename: helloworld.proto package: helloworld; service Greeter { rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {} }</p>
  125. <p class="startli">```</p>
  126. </li>
  127. </ul>
  128. <h2><a class="anchor" id="autotoc_md48"></a>
  129. List methods</h2>
  130. <ul>
  131. <li><p class="startli">List one method with details</p>
  132. <p class="startli"><code>grpc_cli ls</code> command also inspects a method given its full name (in the format of &lt;package&gt;.&lt;service&gt;.&lt;method&gt;).</p>
  133. <p class="startli">```sh $ grpc_cli ls localhost:50051 helloworld.Greeter.SayHello -l ```</p>
  134. <p class="startli"><code>helloworld.Greeter.SayHello</code> is full name of the method.</p>
  135. <p class="startli">output:</p>
  136. <p class="startli">```proto rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {} ```</p>
  137. </li>
  138. </ul>
  139. <h2><a class="anchor" id="autotoc_md49"></a>
  140. Inspect message types</h2>
  141. <p>We can use <code>grpc_cli type</code> command to inspect request/response types given the full name of the type (in the format of &lt;package&gt;.&lt;type&gt;).</p>
  142. <ul>
  143. <li><p class="startli">Get information about the request type</p>
  144. <p class="startli">```sh $ grpc_cli type localhost:50051 helloworld.HelloRequest ```</p>
  145. <p class="startli"><code>helloworld.HelloRequest</code> is the full name of the request type.</p>
  146. <p class="startli">output:</p>
  147. <p class="startli">```proto message HelloRequest { optional string name = 1; } ```</p>
  148. </li>
  149. </ul>
  150. <h2><a class="anchor" id="autotoc_md50"></a>
  151. Call a remote method</h2>
  152. <p>We can send RPCs to a server and get responses using <code>grpc_cli call</code> command.</p>
  153. <ul>
  154. <li><p class="startli">Call a unary method Send a rpc to a helloworld server at <code>localhost:50051</code>:</p>
  155. <p class="startli">``&lsquo;sh $ grpc_cli call localhost:50051 SayHello "name: 'gRPC CLI&amp;rsquo;" ```</p>
  156. <p class="startli">output: <code>sh message: "Hello gRPC CLI"</code></p>
  157. <p class="startli"><code>SayHello</code> is (part of) the gRPC method string. Then &lsquo;"name: 'world&amp;rsquo;"` is the text format of the request proto message. For information on more flags, look at the comments of <code>grpc_cli.cc</code>.</p>
  158. </li>
  159. <li><p class="startli">Use local proto files</p>
  160. <p class="startli">If the server does not have the server reflection service, you will need to provide local proto files containing the service definition. The tool will try to find request/response types from them.</p>
  161. <p class="startli">``&lsquo;sh $ grpc_cli call localhost:50051 SayHello "name: 'world&amp;rsquo;" \ &ndash;protofiles=examples/protos/helloworld.proto ```</p>
  162. <p class="startli">If the proto file is not under the current directory, you can use <code>--proto_path</code> to specify a new search root.</p>
  163. <p class="startli">Note that the tool will always attempt to use the reflection service first, falling back to local proto files if the service is not found. Use <code>--noremotedb</code> to avoid attempting to use the reflection service.</p>
  164. </li>
  165. <li><p class="startli">Send non-proto rpc</p>
  166. <p class="startli">For using gRPC with protocols other than protobuf, you will need the exact method name string and a file containing the raw bytes to be sent on the wire.</p>
  167. <p class="startli">```bash $ grpc_cli call localhost:50051 /helloworld.Greeter/SayHello \ &ndash;input_binary_file=input.bin \ &ndash;output_binary_file=output.bin ```</p>
  168. <p class="startli">On success, you will need to read or decode the response from the <code>output.bin</code> file. </p>
  169. </li>
  170. </ul>
  171. </div></div><!-- contents -->
  172. </div><!-- PageDoc -->
  173. <!-- start footer part -->
  174. <hr class="footer"/><address class="footer"><small>
  175. Generated on Wed Mar 3 2021 19:20:09 for GRPC Objective-C by &#160;<a href="http://www.doxygen.org/index.html">
  176. <img class="footer" src="doxygen.png" alt="doxygen"/>
  177. </a> 1.8.17
  178. </small></address>
  179. </body>
  180. </html>