{"id":154519,"date":"2021-01-14T18:00:53","date_gmt":"2021-01-14T15:00:53","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/"},"modified":"2021-01-14T18:00:53","modified_gmt":"2021-01-14T15:00:53","slug":"how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/","title":{"rendered":"#How to Use HTTPie to Interact With APIs from Your Terminal \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6af0a95229447\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6af0a95229447\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Basic_Commands\" >Basic Commands<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Headers_and_Cookies\" >Headers and Cookies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Working_With_Files\" >Working With Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Sessions\" >Sessions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Managing_Output\" >Managing Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Configuration_File\" >Configuration File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-httpie-to-interact-with-apis-from-your-terminal-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Use HTTPie to Interact With APIs from Your Terminal \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8903\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/b2bfc8e3822b3e5a67b97ab3fc8ce94d\/p\/uploads\/2021\/01\/e70f724b.jpg\" alt=\"Screenshot of HTTPie example request\" width=\"1600\" height=\"900\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/httpie.io\/\">HTTPie<\/a> is an HTTP client for your terminal. Designed as a modern alternative to <code>curl<\/code>, HTTPie simplifies interaction with APIs by offering a straightforward syntax and automatically formatted output.<\/p>\n<p>Available on Windows, Mac and Linux, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/httpie.io\/docs#installation\">getting setup<\/a> should be a straightforward affair. Most Linux distributions now include HTTPie within their package repositories, so you can quickly <code>apt<\/code>, <code>dnf<\/code> or <code>pacman<\/code> to begin. It\u2019s also available via Homebrew for Mac users, and as a Python package delivered via Pip on all three platforms (<code>pip install httpie<\/code>).<\/p>\n<p>Once installed, HTTPie registers the <code>http<\/code> and <code>https<\/code> commands in your shell. You\u2019ve now got a simple and expressive way to call API endpoints without leaving your terminal!<\/p>\n<h2 id=\"basic-commands\"><span class=\"ez-toc-section\" id=\"Basic_Commands\"><\/span>Basic Commands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>At its simplest, HTTPie can be passed a URL to im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely make a <code>GET<\/code> request:<\/p>\n<pre>http example.com<\/pre>\n<p>To send data, specify the <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ropriate HTTP verb and then pass your key\/value pairs as additional command-line parameters:<\/p>\n<pre>http POST example.com foo=bar hello=world<\/pre>\n<p>By default, data is sent as JSON with appropriate request headers. To submit as a form instead, pass the <code>-f<\/code> parameter.<\/p>\n<p>When using the JSON syntax, be aware that all fields are normally sent as strings. You can use the <code>:=<\/code> syntax instead of <code>=<\/code> to switch to raw data mode. A parameter\u00a0<code>examples:='[1, 2]'<\/code> will then result in the <code>examples<\/code> key being set to an array of two integers.<\/p>\n<h2 id=\"headers-and-cookies\"><span class=\"ez-toc-section\" id=\"Headers_and_Cookies\"><\/span>Headers and Cookies<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To set a request header, specify the header\u2019s name and value as a colon-separated string:<\/p>\n<pre>http GET example.com Authorization:foobar<\/pre>\n<p>HTTPie sets some headers, such as <code>User-Agent<\/code>, by default. These can be removed by explicitly specifying them with an empty value.<\/p>\n<p>Cookies are set by defining a string with the cookies as colon-delimited values:<\/p>\n<pre>http GET example.com \"Cookie:foo=bar;hello=world\"<\/pre>\n<p>This is really just a special case of setting the <code>Cookie<\/code> header, which is how cookies are sent over HTTP.<\/p>\n<h2 id=\"working-with-files\"><span class=\"ez-toc-section\" id=\"Working_With_Files\"><\/span>Working With Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can upload and download files using standard shell redirects:<\/p>\n<pre>http POST example.com\/upload &lt; ~\/example.pdf&#13;\nhttp GET example.com\/download.pdf &gt; ~\/download.pdf<\/pre>\n<p>You can also upload files as part of an HTTP form submission by using the special <code>@<\/code> syntax:<\/p>\n<pre>http -f POST example.com\/form-with-file hello=\"Hello World\" myUpload@~\/example.pdf<\/pre>\n<p>This will act identically to an HTML file input with <code>name=\"myUpload\"<\/code>. You may instead load data from a file and embed it into the request using the <code>=@<\/code> syntax, instead of <code>@<\/code>.<\/p>\n<h2 id=\"sessions\"><span class=\"ez-toc-section\" id=\"Sessions\"><\/span>Sessions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>HTTPie has built-in support for persistent sessions. These allow you to reuse request components, such as HTTP headers and cookies, between requests made to the same host.<\/p>\n<p>You create and use sessions by setting the <code>--session<\/code> parameter. As its value, specify the path to a file which will be used to store your new session.<\/p>\n<pre>http --session=.\/my-session.json GET example.com Authorization:foobar<\/pre>\n<p>Data which is supported by sessions, such as the <code>Authorization<\/code> header in the above request, will now be saved into the file. On subsequent requests, you may now omit the <code>Authorization<\/code> header \u2013 it\u2019ll be included automatically as it\u2019s defined in your session.<\/p>\n<p>Instead of specifying a session file, you may also use a simple name (<code>--session=example<\/code>). In this case, HTTPie will automatically save the session to an internally managed file. Each session is tied to the host it originates from, so <code>http --session=example example1.com<\/code> and <code>http --session=example example2.com<\/code> will exist independently of each other.<\/p>\n<h2 id=\"managing-output\"><span class=\"ez-toc-section\" id=\"Managing_Output\"><\/span>Managing Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One of HTTPie\u2019s significant improvements over utilities like <code>curl<\/code> is its automatic formatting of responses. JSON bodies are particularly well-handled, with proper indentation, alphabetical sorting of objects by their keys and correct conversion of Unicode characters.<\/p>\n<p>You can customise how output is rendered using a few different options. The <code>--pretty<\/code> flag can be set to <code>--all<\/code> (default), <code>--colors<\/code> (only colours), <code>--format<\/code> (only formatting) or <code>--none<\/code> (to disable all output processing and see the raw data).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8908\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/f1d6fcef4b27c0c883353ce799c267b1\/p\/uploads\/2021\/01\/1b4e3802.jpeg\" alt=\"Screenshot of HTTPie JSON output\" width=\"967\" height=\"542\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>In addition, you can change the colour scheme using the <code>--style<\/code> flag. The available schemes are <code>auto<\/code> (the default), <code>default<\/code> (use the underlying Pygments library styles), <code>fruity<\/code> and the popular <code>monokai<\/code>.<\/p>\n<p>You don\u2019t need to worry about the default formatting when redirecting output into a file. HTTPie will recognise that it\u2019s being redirected and simply pipe the raw data without applying any formatting. This also means that binary responses, which are never normally emitted to the terminal, can be piped into files.<\/p>\n<h2 id=\"configuration-file\"><span class=\"ez-toc-section\" id=\"Configuration_File\"><\/span>Configuration File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>HTTPie supports a basic configuration file which can be used to define default settings. These will be applied to all requests you make. The file should be saved to <code>~\/.config\/httpie\/config.json<\/code> on Linux\/Mac and <code>%APPDATA%httpieconfig.json<\/code> on Windows.<\/p>\n<p>A single configuration key is supported, <code>default_options<\/code>, which accepts a basic array of parameters to append to HTTPie commands you execute:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"json\">\n<pre class=\"de1\">{&#13;\n    \"default_options\": [&#13;\n        \"Authorization:foobar\",&#13;\n        \"--pretty=none\",&#13;\n        \"--style=monokai\"&#13;\n    ]&#13;\n}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Any option which is supported by HTTPie\u2019s command-line interface can be included. You can override your default options by defining them with a new value each time you run HTTPie.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/httpie.io\/\">HTTPie<\/a> is a feature-filled tool that brings HTTP APIs to your terminal. Its a modern alternative to Unix staples like <code>curl<\/code> that\u2019s designed for regular use by developers and testers. Although the syntax can be cumbersome at times, it\u2019s <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly expressive and memorable.<\/p>\n<p>It\u2019s worth taking the time to read the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/httpie.io\/docs\">official documentation<\/a> if you\u2019re looking to learn more about HTTPie. All development occurs in the open on <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/jkbr\/httpie\/issues\">GitHub<\/a>, with support provided on <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/gitter.im\/jkbrzt\/httpie\">Gitter<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/stackoverflow.com\/questions\/tagged\/httpie\">StackOverflow<\/a>.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/8902\/how-to-use-httpie-to-interact-with-apis-from-your-terminal\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Use HTTPie to Interact With APIs from Your Terminal \u2013 CloudSavvy IT&#8221; HTTPie is an HTTP client for your terminal. Designed as a modern alternative to curl, HTTPie simplifies interaction with APIs by offering a straightforward syntax and automatically formatted output. Available on Windows, Mac and Linux, getting setup should be a straightforward&#8230;<\/p>\n","protected":false},"author":1,"featured_media":154520,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/01\/e70f724b.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-154519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/154519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=154519"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/154519\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/154520"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=154519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=154519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=154519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}