-
-
Save dvcolgan/2f9ff9636388cf70f2f7bd1a3d2de09f to your computer and use it in GitHub Desktop.
A simple http command line client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: