Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

256 lines (255 sloc) 10.115 kb
#N canvas 369 82 914 513 10;
#N canvas 258 54 853 470 CouchDB-basics 0;
#X text 416 71 CRUD documents:;
#X text 15 10 Basic CRUD methods for databases and individual documents
are done with three HTTP methods: PUT \, GET and DELETE. PUT is used
for creating and updating data \, GET is used for retrieving data \,
while DELETE is used for deleting data. This is best explained with
some examples:;
#X text 15 74 CRUD databases:;
#X text 15 93 PUT http://localhost:5984/pd-test;
#X text 14 105 This will create a database "pd-test" on the server
localhost. If the operation is successful \, CouchDB will return a
JSON object starting with a key of "ok" and a message as value for
that key. If creating the database is not possible \, you will get
a key "error" and the reason for the failure as its value.;
#X text 15 178 GET http://localhost:5984/pd-test;
#X text 15 191 This will get some info on the database \, including
the count of stored documents as "doc_count". If getting the database
is not possible you will receive a key "error" and the reason for the
failure as its value.;
#X text 15 242 DELETE http://localhost:5984/pd-test;
#X text 15 258 This will delete the database if possible. BEWARE: You
won't get prompted for confirmation \, CouchDB will delete the database
without any warning including all stored documents. This will return
"ok" or "error" as a key.;
#X text 416 116 This will create or update a document with the ID "object-name"
in the database "pd-test". The database must be created first. If a
document with the ID "object-name" already exists \, you must include
the revision \, that you can get with the GET method (see below). On
error CouchDB will return a key of "error" and the reason for the error
as its value. Data for the object must be provided as JSON data in
the request header.;
#X text 416 208 GET http://localhost:5984/pd-test/object-name;
#X text 417 222 This will retrieve the document "object-name" from
the database "pd-test". This will return the document as a JSON object
\, including the ID with the key "_id" and the revision code with the
key "_rev". The latter value is needed for updating or deleting the
object from the table to prevent concurrent updates.;
#X text 417 292 DELETE http://localhost:5984/pd-test/object-name;
#X text 418 311 This will delete the document if possible. You will
need to provide the revision for the document. You will receive data
with a key of "ok" or "error" and information as value.;
#X text 416 91 PUT http://localhost:5984/pd-test/object-name data-as-json-string
;
#X text 15 362 All these request \, PUT \, GET and DELETE can be done
with [rest-json] \, you can even issue POST requests to a CouchDB server.
If you want to do complex data operations on a CouchDB \, please refer
to the manual: http://guide.couchdb.org/;
#X restore 20 277 pd CouchDB-basics;
#X obj 21 211 json-decode;
#X obj 20 158 rest-json http://localhost:5984/;
#X obj 19 -60 rest-json;
#N canvas 196 0 932 709 couchdb 0;
#X msg 603 26 bang;
#X msg 59 19 url http://localhost:5984/;
#X obj 171 279 list trim;
#X obj 170 310 route error ok;
#X msg 179 377 0;
#X obj 261 266 t b b;
#X msg 261 293 1;
#X text 99 359 Close signal flow on error;
#X obj 55 427 print error message;
#X text 320 301 Reopen signal flow after each object.;
#X obj 210 335 print OK message;
#N canvas 576 82 450 345 create-sequencer-data 0;
#X obj 32 12 inlet;
#X obj 32 291 outlet;
#X obj 62 222 + 1;
#X obj 32 253 pack f s;
#X obj 32 166 json-encode;
#X msg 32 84 add pitch 440 \, add duration 2000 \, bang \, clear \,
add pitch 880 \, add duration 1000 \, bang \, clear \, add pitch 440
\, add duration 1000 \, bang \, clear \, add pitch 1320 \, add duration
500 \, bang \, clear \, add pitch 880 \, add duration 2000 \, bang
\, clear;
#X obj 32 193 t b a;
#X obj 32 222 0;
#X obj 32 49 t b b;
#X msg 110 166 0;
#X connect 0 0 8 0;
#X connect 2 0 7 1;
#X connect 3 0 1 0;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 6 1 3 1;
#X connect 7 0 2 0;
#X connect 7 0 3 0;
#X connect 8 0 5 0;
#X connect 8 1 9 0;
#X connect 9 0 7 1;
#X restore 603 53 pd create-sequencer-data;
#X text 58 -2 1 Sets the base URL.;
#X text 243 -6 2 Creates database pd-test on server with base URL.
If you do not set the base URL \, then you can also issue this command
with [PUT http://localhost:5984/pd-test/(;
#X text 600 -2 3 Creates some sequencer data and stores the data in
pd-test. Objects contain "pitch" and "duration".;
#X text 45 93 4 Start sequencer and get first object;
#X obj 46 140 f;
#X obj 74 142 + 1;
#X obj 316 386 route pitch duration;
#X obj 288 418 pack f f f;
#X obj 216 494 unpack f f f;
#X obj 285 520 del;
#X text 343 446 first inlet of pack is not used. The reason for that
is explained in the help patch for;
#X obj 539 462 json-decode;
#X obj 26 294 print data;
#X text 602 131 5 Get database pd-test;
#X text 606 175 6 Delete database pd-test;
#X msg 603 154 GET pdtest;
#X msg 248 35 PUT pdtest;
#X msg 603 77 PUT pdtest/\$1 \$2;
#X msg 608 193 DELETE pdtest;
#X msg 46 169 GET pdtest/\$1;
#X text 58 -37 This example will create a database and store values
to be used by a simple sequencer.;
#X msg 46 112 0;
#X obj 216 463 spigot 1;
#X obj 295 107 spigot;
#X obj 328 73 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 603 102 print Put command;
#X obj 139 332 t b a b;
#X text 275 57 toggle only when using sequencer;
#X msg 32 366 0;
#X text 4 343 restart GET sequence;
#X obj 171 244 rest-json;
#X obj 250 540 osc~;
#X obj 311 587 *~ 0;
#X obj 311 613 dac~;
#X connect 0 0 11 0;
#X connect 1 0 42 0;
#X connect 2 0 3 0;
#X connect 3 0 38 0;
#X connect 3 1 10 0;
#X connect 3 2 18 0;
#X connect 4 0 34 1;
#X connect 5 0 6 0;
#X connect 5 1 19 0;
#X connect 6 0 34 1;
#X connect 11 0 29 0;
#X connect 16 0 17 0;
#X connect 16 0 31 0;
#X connect 17 0 16 1;
#X connect 18 0 19 1;
#X connect 18 1 19 2;
#X connect 19 0 34 0;
#X connect 20 1 43 0;
#X connect 20 2 21 0;
#X connect 21 0 35 0;
#X connect 27 0 42 0;
#X connect 28 0 42 0;
#X connect 29 0 37 0;
#X connect 29 0 42 0;
#X connect 30 0 42 0;
#X connect 31 0 42 0;
#X connect 33 0 16 0;
#X connect 34 0 20 0;
#X connect 35 0 16 0;
#X connect 36 0 35 1;
#X connect 36 0 44 1;
#X connect 38 0 40 0;
#X connect 38 1 8 0;
#X connect 38 2 4 0;
#X connect 40 0 35 0;
#X connect 42 0 2 0;
#X connect 42 0 24 0;
#X connect 42 1 5 0;
#X connect 43 0 44 0;
#X connect 44 0 45 0;
#X connect 44 0 45 1;
#X restore 19 351 pd couchdb;
#X obj 458 216 rest-json;
#X msg 497 124 GET http://search.twitter.com/search.json?q=%23puredata
;
#X msg 474 64 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
;
#X msg 458 10 GET https://github.com/api/v2/json/commits/list/residuum/PuRestJson/master
;
#X text 76 -59 - object for HTTP communication with REST webservices
;
#X text 19 258 An example for a RESTful interface is CouchDB:;
#X text 17 -33 [rest-json] is an object for communication with REST
services that return JSON data. Request methods GET \, POST \, PUT
and DELETE are available.;
#X text 17 4 All requests are issued with [REQUEST_METHOD URL DATA(
where REQUEST_METHOD is the uppercase verb of the method \, URL is
the request URL \, or the relative server path \, if [url( or initialization
is used \, and DATA is the upload data for PUT or post data for POST.
;
#X text 17 302 Here is a complex example for using [rest-json] to communicate
with CouchDB. It uses GET \, POST and DELETE request methods. You will
need to have a local installation of CouchDB.;
#X text 18 61 HTTP requests are asynchronous. Do not expect two subsequent
requests to arrive in the same order as sending them. [rest-json] does
all its work in separate threads.;
#X obj 458 248 print data;
#X text 18 99 Set the base url at creation or use [url( message. An
empty url message will clean a previous set base url. You can also
use four parameters for the [url( message to use basic cookie authentication
\, see below.;
#N canvas 504 82 450 300 OAUTH 0;
#X text 68 54 OAUTH is not yet implemented. Sorry about that.;
#X restore 462 390 pd OAUTH;
#X text 461 372 When OAUTH is implemented \, you will find infos about
it here;
#X text 18 385 Using cookie authentication with rest-json;
#N canvas 500 78 443 465 cookie-auth 0;
#X obj 40 347 rest-json;
#X text 35 12 Basic cookie authentication is possible with [rest-json]
\, as long as the service uses some guidelines \, that are adopted
from CouchDB.;
#X obj 37 66 rest-json http://example.com/ login-page myusername mypass
;
#X text 34 91 This will try to log you in on creation. It will call
the url http://example.com/login-page and post username=myusername&password=mypass
to the page.;
#X text 34 128 When this returns a cookie \, the cookie will be saved
and included in every request \, as long as the base url does not change.
;
#X text 35 168 Please keep in mind \, that passwords in Pd patches
are stored in plain text \, especially when you use code hosting services.
Better store your passwords in a seperate file or application and use
[textfile] or OSC for getting the data.;
#X obj 40 273 rest-json http://example.com/ login-page myusername mypass
;
#X msg 40 313 url http://example.com/ login-page myusername mypass
;
#X text 39 254 This;
#X text 39 293 is the same as this after clicking the [url( message
;
#X text 38 374 To clear your stored authentication cookie \, send a
[url( message with no additional parameters \, or with only one parameter.
The latter will send only the base url \, but will not try to log you
in.;
#X connect 7 0 0 0;
#X restore 19 403 pd cookie-auth;
#X text 18 184 [rest-json] gets data as JSON objects \, output on the
first two outlets is the same as;
#X text 18 229 The third outlet will output status information of the
request;
#X obj 537 248 print done;
#X obj 608 248 print status;
#X text 497 170 This will give you an error on the third outlet;
#X msg 499 188 GET http://search.twitter.com/wrongsearch.json?q=%23puredata
;
#X connect 5 0 15 0;
#X connect 5 1 23 0;
#X connect 5 2 24 0;
#X connect 6 0 5 0;
#X connect 7 0 5 0;
#X connect 8 0 5 0;
#X connect 26 0 5 0;
Jump to Line
Something went wrong with that request. Please try again.