Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to <a href="https://stackoverflow.com/questions/11647656/getting-bad-request-invalid-json-error-when-trying-to-insert-document-into-co#answer-11649320"><code>Ruben Verborgh</code></a>, I compiled micro-tutorial from several sources myself.</p> <pre><code>var http = require('http') var sys = require('sys') var couchdbPath = 'http://localhost:5984/' request = require('request') h = {accept: 'application/json', 'content-type': 'application/json'} request( {uri: couchdbPath + '_all_dbs', headers:h}, function(err, response, body) { console.log(sys.inspect(JSON.parse(body))); } ) // add database request( {uri: couchdbPath + 'dbname', method:'PUT', headers:h}, function (err, response, body) { if (err) throw err; if (response.statusCode !== 201) throw new Error("Could not create database. " + body); } ) // Modify existing document var options = { host: "localhost", port: 5984, path: "/dbname", headers: {"content-type": "application/json"}, method: "PUT" }; var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); //console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); req.on('error', function(e) { console.log('problem with request: ' + e.message); }); // write data to request body req.write(JSON.stringify({ "_id":"rabbit", "_rev":"4-8cee219da7e61616b7ab22c3614b9526", "Subject":"I like Plankton" })); req.end(); </code></pre> <p>I used following documentation:</p> <ul> <li><a href="http://nodejs.org/api/http.html#http_http_request_options_callback" rel="nofollow noreferrer"><code>http.request()</code></a> </li> <li><a href="http://wiki.apache.org/couchdb/Complete_HTTP_API_Reference" rel="nofollow noreferrer">CouchDB Complete HTTP API Reference</a> </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload