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

255 lines (254 sloc) 9.951 kb
#N canvas 353 66 952 532 10;
#X declare -lib purest_json;
#N canvas 256 52 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 236 pd CouchDB-basics;
#N canvas 194 51 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 574 80 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 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 250 540 osc~;
#X obj 311 587 *~ 0;
#X obj 311 613 dac~;
#X obj 171 250 json-decode;
#X obj 171 217 rest;
#X connect 0 0 11 0;
#X connect 1 0 44 0;
#X connect 2 0 3 0;
#X connect 3 0 36 0;
#X connect 3 1 10 0;
#X connect 3 2 18 0;
#X connect 4 0 32 1;
#X connect 5 0 6 0;
#X connect 5 1 19 0;
#X connect 6 0 32 1;
#X connect 11 0 27 0;
#X connect 16 0 17 0;
#X connect 16 0 29 0;
#X connect 17 0 16 1;
#X connect 18 0 19 1;
#X connect 18 1 19 2;
#X connect 19 0 32 0;
#X connect 20 1 40 0;
#X connect 20 2 21 0;
#X connect 21 0 33 0;
#X connect 25 0 44 0;
#X connect 26 0 44 0;
#X connect 27 0 35 0;
#X connect 27 0 44 0;
#X connect 28 0 44 0;
#X connect 29 0 44 0;
#X connect 31 0 16 0;
#X connect 32 0 20 0;
#X connect 33 0 16 0;
#X connect 34 0 33 1;
#X connect 34 0 41 1;
#X connect 36 0 38 0;
#X connect 36 1 8 0;
#X connect 36 2 4 0;
#X connect 38 0 33 0;
#X connect 40 0 41 0;
#X connect 41 0 42 0;
#X connect 41 0 42 1;
#X connect 43 0 2 0;
#X connect 43 1 5 0;
#X connect 44 0 22 0;
#X connect 44 0 43 0;
#X restore 19 310 pd couchdb;
#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 text 55 -59 - object for HTTP communication with REST webservices
;
#X text 19 217 An example for a RESTful interface is CouchDB:;
#X text 17 -3 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 261 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 obj 458 389 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.;
#X text 18 344 Using cookie authentication with rest-json;
#N canvas 498 76 443 465 cookie-auth 0;
#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 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 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 obj 37 66 rest http://example.com/ login-page myusername mypass
;
#X obj 40 273 rest http://example.com/ login-page myusername mypass
;
#X obj 40 347 rest;
#X connect 4 0 10 0;
#X restore 19 362 pd cookie-auth;
#X obj 540 389 print status;
#X msg 499 188 GET http://search.twitter.com/wrongsearch.json?q=%23puredata
;
#X obj 457 -40 import purest_json;
#X obj 19 -60 rest;
#X text 17 -33 [rest] is an object for communication with REST services.
Request methods GET \, POST \, PUT and DELETE are available.;
#X text 18 61 HTTP requests are asynchronous. Do not expect a request
to return data immediately. While one request is processed \, the object
id blocked.;
#X obj 20 158 rest http://localhost:5984/;
#X text 18 188 The second outlet will output status information of
the request;
#X obj 458 357 rest;
#X text 497 170 This will give you an error message on the second outlet
;
#X text 517 217 By default \, requests do not timeout. To set a maximal
time in milliseconds \, set a value with [timeout( message. To clear
the value and return to the default \, use an empty [timeout( message.
;
#X msg 457 10 GET https://api.github.com/repos/residuum/PuRestJson/contents/Makefile
;
#X msg 520 271 timeout 2000;
#X msg 536 303 timeout;
#X connect 2 0 20 0;
#X connect 3 0 20 0;
#X connect 13 0 20 0;
#X connect 20 0 8 0;
#X connect 20 1 12 0;
#X connect 23 0 20 0;
#X connect 24 0 20 0;
#X connect 25 0 20 0;
Jump to Line
Something went wrong with that request. Please try again.