{"id":1444,"date":"2020-09-04T16:30:52","date_gmt":"2020-09-04T16:30:52","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=1444"},"modified":"2020-09-04T16:30:52","modified_gmt":"2020-09-04T16:30:52","slug":"command-line-http-apps","status":"publish","type":"post","link":"https:\/\/sdi.thoughtstorms.info\/?p=1444","title":{"rendered":"Command line HTTP apps."},"content":{"rendered":"<p>I just rediscovered a question I wrote on Stack Exchange. I can&#8217;t remember much about the context, but the idea is to have an ordinary &#8220;web server&#8221; application accessed through http, but simply sending plain-text backwards and forwards to a command-line based client.<\/p>\n<p><em><a href=\"https:\/\/unix.stackexchange.com\/questions\/310377\/is-there-a-terminal-style-program-that-talks-to-a-server-over-http?noredirect=1#comment545785_310377\">command line &#8211; Is there a &#8220;terminal&#8221; style program that talks to a server over http? &#8211; Unix &amp; Linux Stack Exchange<\/a><\/em><\/p>\n<p>The question was :<\/p>\n<p>I&#8217;m looking for something that acts like a terminal but lets me have a &#8220;dialogue&#8221; with a server over http. Something like this :<\/p>\n<pre><code>\n$ connect http:\/\/myserver.com\nWelcome to myserver.com\nOptions\nA - Fribble the obsticator\nB - List Frogits\nC - Show the log\nQ - Quit\n$ A\nObsticator fribbled\nblah blah\nblah\n$ C\nLog file\n...\n$ Q\nBye\n<\/code><\/pre>\n<p>Http is a useful protocol and it goes everywhere, it&#8217;s easy to write a server that handles it (thanks to libraries). But you aren&#8217;t always in a place where you have a browser or could run one. Sure there are browsers like lynx etc. that run in the terminal, but they aren&#8217;t particularly easy. Sometimes you just want something that&#8217;s more like the old <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gopher_(protocol)\">Gopher<\/a> etc. systems. But with the benefits of modern server technology.<\/p>\n<p>No-one seems to have written one, so I mocked up a client in Python using the Requests (<a href=\"http:\/\/requests.readthedocs.io\/en\/master\/\" rel=\"nofollow\">http:\/\/requests.readthedocs.io\/en\/master\/<\/a>) library :<\/p>\n[cc language=&#8221;python&#8221;]\nimport requests\nimport sys\nurl = sys.argv[1]\nprint &#8220;Connecting &#8220;, url\nr = requests.get(url)\nprint r.text\nflag = True\nwhile flag :\n    s = raw_input()\n    data = {&#8220;opt&#8221;: s}\n    r = requests.get(url, params=data)\n    print r.text\n[\/cc]\n\n<p>A server now just has to respond to messages passed as &#8220;opt&#8221; on a particular URL, and to respond in plain-text. <\/p>\n\n\n<p>Obviously, something like file-downloads etc. would also be useful. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just rediscovered a question I wrote on Stack Exchange. I can&#8217;t remember much about the context, but the idea is to have an ordinary &#8220;web server&#8221; application accessed through http, but simply sending plain-text backwards and forwards to a command-line based client. command line &#8211; Is there a &#8220;terminal&#8221; style program that talks to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[79,365,496],"class_list":["post-1444","post","type-post","status-publish","format-standard","hentry","category-zeitgeist","tag-command-line","tag-python","tag-web-apps"],"_links":{"self":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1444"}],"version-history":[{"count":0,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1444\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}