Skip to content

Instantly share code, notes, and snippets.

@domgiles
Created October 7, 2016 21:53
Show Gist options
  • Save domgiles/4d1a9c46cd86e79cce6a505e97b23762 to your computer and use it in GitHub Desktop.
Save domgiles/4d1a9c46cd86e79cce6a505e97b23762 to your computer and use it in GitHub Desktop.
import json
import requests
url = 'http://tpc12server:8080/ords/soe/soda/latest/OrdersCollection'
# Delete Collection
response = requests.delete(url)
# Create Collection
response = requests.put(url)
# Get Data from Collection, Zero rows
response = requests.get(url)
print response.text
# Insert some data
data = {"id": 1, "SomeData": "Some Data in the document"}
response = requests.post(url, json=data)
print response.text
# Get the id of the first document in the collection from the response
j_response = json.loads(response.text)
id = j_response["items"][0]["id"]
# Get the row from it's id
response = requests.get(url + "/" + id)
print response.text
# Delete the document from the collection
response = requests.delete(url + "/" + id)
print response.status_code
# Array insert multiple documents
data = [{"id": 1, "SomeData": "Some Data in the document"},
{"id": 2, "SomeData": "Some more Data in the document"},
{"id": 3, "SomeData": "Some more more Data in the document"},
{"id": 4, "SomeData": "Some more more more Data in the document"},
{"id": 5, "SomeData": "Some more more more more Data in the document"}]
j_response = json.loads(requests.post(url + "?action=insert", json=data).text)
# Get ids of documents inserted
for doc in j_response["items"]:
print doc["id"]
# Simple QBE
qbe = {"SomeData": "Some more Data in the document"}
j_response = json.loads(requests.post(url + "?action=query",json=qbe).text)
print json.dumps(j_response["items"][0]["value"])
# or statement
qbe = {"$or" : [{"SomeData": "Some more Data in the document"}, {"SomeData": "Some more more more more Data in the document"}]}
j_response = json.loads(requests.post(url + "?action=query",json=qbe).text)
for doc in j_response["items"]:
print doc["id"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment