|
| 1 | +.. _CLI: |
| 2 | + |
| 3 | +Hyper Command Line Interface |
| 4 | +============================ |
| 5 | + |
| 6 | +For testing purposes, ``hyper`` provides a command-line tool that can make |
| 7 | +HTTP/2 requests directly from the CLI. This is useful for debugging purposes, |
| 8 | +and to avoid having to use the Python interactive interpreter to execute basic |
| 9 | +queries. |
| 10 | + |
| 11 | +The usage is:: |
| 12 | + |
| 13 | + hyper [-h] [--version] [--debug] [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]] |
| 14 | + |
| 15 | +For example: |
| 16 | + |
| 17 | +.. code-block:: bash |
| 18 | +
|
| 19 | + $ hyper GET https://nghttp2.org/httpbin/get |
| 20 | + {'args': {}, |
| 21 | + 'headers': {'Connection': 'close', 'Host': 'httpbin', 'Via': '2.0 nghttpx'}, |
| 22 | + 'origin': '81.129.184.72', |
| 23 | + 'url': 'https://httpbin/get'} |
| 24 | +
|
| 25 | +This allows making basic queries to confirm that ``hyper`` is functioning |
| 26 | +correctly, or to perform very basic interop testing with other services. |
| 27 | + |
| 28 | +Sending Data |
| 29 | +------------ |
| 30 | + |
| 31 | +The ``hyper`` tool has a limited ability to send certain kinds of data. You can |
| 32 | +add extra headers by passing them as colon-separated data: |
| 33 | + |
| 34 | +.. code-block:: bash |
| 35 | +
|
| 36 | + $ hyper GET https://nghttp2.org/httpbin/get User-Agent:hyper/0.2.0 X-Totally-Real-Header:someval |
| 37 | + {'args': {}, |
| 38 | + 'headers': {'Connection': 'close', |
| 39 | + 'Host': 'httpbin', |
| 40 | + 'User-Agent': 'hyper/0.2.0', |
| 41 | + 'Via': '2.0 nghttpx', |
| 42 | + 'X-Totally-Real-Header': 'someval'}, |
| 43 | + 'origin': '81.129.184.72', |
| 44 | + 'url': 'https://httpbin/get'} |
| 45 | +
|
| 46 | +You can add query-string parameters: |
| 47 | + |
| 48 | +.. code-block:: bash |
| 49 | +
|
| 50 | + $ hyper GET https://nghttp2.org/httpbin/get search==hyper |
| 51 | + {'args': {'search': 'hyper'}, |
| 52 | + 'headers': {'Connection': 'close', 'Host': 'httpbin', 'Via': '2.0 nghttpx'}, |
| 53 | + 'origin': '81.129.184.72', |
| 54 | + 'url': 'https://httpbin/get?search=hyper'} |
| 55 | +
|
| 56 | +And you can upload JSON objects: |
| 57 | + |
| 58 | +.. code-block:: bash |
| 59 | +
|
| 60 | + $ hyper POST https://nghttp2.org/httpbin/post name=Hyper language=Python description='CLI HTTP client' |
| 61 | + {'args': {}, |
| 62 | + 'data': '{"name": "Hyper", "description": "CLI HTTP client", "language": ' |
| 63 | + '"Python"}', |
| 64 | + 'files': {}, |
| 65 | + 'form': {}, |
| 66 | + 'headers': {'Connection': 'close', |
| 67 | + 'Content-Length': '73', |
| 68 | + 'Content-Type': 'application/json; charset=utf-8', |
| 69 | + 'Host': 'httpbin', |
| 70 | + 'Via': '2.0 nghttpx'}, |
| 71 | + 'json': {'description': 'CLI HTTP client', |
| 72 | + 'language': 'Python', |
| 73 | + 'name': 'Hyper'}, |
| 74 | + 'origin': '81.129.184.72', |
| 75 | + 'url': 'https://httpbin/post'} |
| 76 | +
|
| 77 | +Debugging and Detail |
| 78 | +-------------------- |
| 79 | + |
| 80 | +For more detail, passing the ``--debug`` flag will enable ``hyper``'s |
| 81 | +DEBUG-level logging. This provides a lot of low-level detail about exactly what |
| 82 | +``hyper`` is doing, including sent and received frames and HPACK state. |
| 83 | + |
| 84 | +Notes |
| 85 | +----- |
| 86 | + |
| 87 | +The ``hyper`` command-line tool is not intended to be a fully functional HTTP |
| 88 | +CLI tool: for that, we recommend using `HTTPie`_, which uses ``hyper`` for its |
| 89 | +HTTP/2 support. |
| 90 | + |
| 91 | +.. _HTTPie: https://github.com/jakubroztocil/httpie-http2 |
0 commit comments