Command line HTTP apps.

I just rediscovered a question I wrote on Stack Exchange. I can’t remember much about the context, but the idea is to have an ordinary “web server” application accessed through http, but simply sending plain-text backwards and forwards to a command-line based client.

command line – Is there a “terminal” style program that talks to a server over http? – Unix & Linux Stack Exchange

The question was :

I’m looking for something that acts like a terminal but lets me have a “dialogue” with a server over http. Something like this :

$ connect
Welcome to
A - Fribble the obsticator
B - List Frogits
C - Show the log
Q - Quit
$ A
Obsticator fribbled
blah blah
$ C
Log file
$ Q

Http is a useful protocol and it goes everywhere, it’s easy to write a server that handles it (thanks to libraries). But you aren’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’t particularly easy. Sometimes you just want something that’s more like the old Gopher etc. systems. But with the benefits of modern server technology.

No-one seems to have written one, so I mocked up a client in Python using the Requests ( library :

[cc language=”python”]
import requests
import sys
url = sys.argv[1]
print “Connecting “, url
r = requests.get(url)
print r.text
flag = True
while flag :
s = raw_input()
data = {“opt”: s}
r = requests.get(url, params=data)
print r.text

A server now just has to respond to messages passed as “opt” on a particular URL, and to respond in plain-text.

Obviously, something like file-downloads etc. would also be useful.

Leave a comment