Skip to content

Instantly share code, notes, and snippets.

@allexiusw
Last active November 15, 2019 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allexiusw/21773a151f5d55f3acd5e4575009a673 to your computer and use it in GitHub Desktop.
Save allexiusw/21773a151f5d55f3acd5e4575009a673 to your computer and use it in GitHub Desktop.
REST curl CouchDB
#set your public or local ip
IP="54.222.100.10"
#check server status
curl -X GET http://$IP:5984
#list all databases
curl -X GET http://$IP:5984/_all_dbs
#set your db_name
MY_DB="nueva_db"
#create your database
curl -X PUT user:pass@$IP:5984/$MY_DB
#Set your document id
ID=1
#Create new document
curl -X PUT $IP:5984/$MY_DB/$ID -d ‘{ “codigo”: “SMIS052323”, “name”:
“Luis” }’
#Create new document
curl -X POST $IP:5984/$MY_DB -d ‘{ “codigo”: “SMIS052323”, “name”: “Luis” }’
#get Document
curl -X GET $IP:5984/$MY_DB/$ID
#Set the revision id document to update
REV="REVISION_ID"
#update document
curl -X PUT $IP:5984/$MY_DB/$ID -d ‘{ “codigo”: “SMIS052323”, “name”: “Luis Vaquerano Sierra”, “_rev” : ”REVISION_ID” }’
#Set the revision id document to delete
REV="REVISION_ID"
#Delete document
curl -X DELETE $IP:5984/$MY_DB/$ID -d ‘{ “_rev”:$REV }’
#Get all
curl -X POST $IP:5984/$MY_DB/_find -d ‘{ “selector”: {} }’
#Get by id
curl -X POST $IP:5984/$MY_DB/_find -d ‘{ “selector”: {“codigo”: {“$eq: $ID} } }’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment