Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created August 30, 2012 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjgiridhar/3526524 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3526524 to your computer and use it in GitHub Desktop.
Tornado - Mongo - Client
import httplib2
from urllib import urlencode
h = httplib2.Http()
## Add articles
data = {'id':'1', 'author':'B', 'genre':'comedy'}
body = urlencode(data)
h.request("http://127.0.0.1:8888/articles", "POST", body=body)
data = {'id':'2', 'author':'A', 'genre':'tragedy'}
body = urlencode(data)
h.request("http://127.0.0.1:8888/articles", "POST", body=body)
## View all articles
content, response = h.request("http://127.0.0.1:8888/articles", "GET")
print response
## View articles
data = {"articleid":1}
data = urlencode(data)
content, response = h.request("http://127.0.0.1:8888/articles"+ "?" + data, "GET")
print response
## Delete articles
content, response = h.request("http://127.0.0.1:8888/articles", "DELETE")
content, response = h.request("http://127.0.0.1:8888/articles", "GET")
print response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment