Skip to content

Instantly share code, notes, and snippets.

@dvcolgan
Last active April 25, 2016 18:29
Show Gist options
  • Save dvcolgan/2f9ff9636388cf70f2f7bd1a3d2de09f to your computer and use it in GitHub Desktop.
Save dvcolgan/2f9ff9636388cf70f2f7bd1a3d2de09f to your computer and use it in GitHub Desktop.
A simple http command line client
#!/usr/bin/python2.7
import sys
import requests
import json
contents = json.loads(open('.httprc').read())
url_prefix = contents['url_prefix']
method = sys.argv[1].lower()
url = sys.argv[2]
url = url_prefix + url
# Allow putting in json without quote marks by mushing together all the other arguments
payload = ' '.join(sys.argv[3:]).strip()
response = requests.request(method, url, json=payload)
print response.status_code
print response.json()
@dvcolgan
Copy link
Author

Put this in a file called "req", put it in your path, install Python2 requests through your OS's package manager, and then you can do things like:

req GET /api/foo
req POST /api/foo/ {"bar": "baz"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment