CouchDB gives me no REST

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
hliljegren
Posts: 107
Joined: Sun Aug 23, 2009 7:48 am
Contact:

CouchDB gives me no REST

Post by hliljegren » Wed May 10, 2017 3:51 pm

Hi!

Trying to do some basic operations with CouchDB via it's REST interface. Running curl from the command line works perfectly but trying from LiveCode is currently only partially working. I guess it's me but if someone could share some light I would be really grateful!

Example 1
I would like to create a new CouchDB data base. The working curl for this is:

Code: Select all

curl -u user:passwd -X PUT http://127.0.0.1:5984/newdb
-or- 
curl -X PUT http://user:passwd@127.0.0.1:5984/newdb
I need to use PUT, but there is no data to be submitted, so I tried:

Code: Select all

put empty into url "http://user:password@127.0.0.1:5984/newdb
but if I check the libURLLastRHHeaders I can see that I get a 401: Unauthorized response from CouchDB. I've tried to change the user and password to something really simple like "test:test" to ensure that there is no strange character error but still the same result.

Example 2
If I try to insert data into already existing database. i.e. the curl equivalent of:

Code: Select all

curl -X PUT http://user:passwd@127.0.0.1:5984/mydb/my-test-post -d '{"hello":"world"}'
I then used:

Code: Select all

put "{" & q("World") & colon & q("Hello") &  "}" into url "http://user:passwd@127.0.0.1:5984/mydb/my-other-test"
It does work and I get a new document in the couchDB. (q() is just a small function that returns the string quoted.)

So, I guess there is something going on when I try to use put but doesn't in fact "PUT" anything...

BTW

Code: Select all

delete url http://user:passwd@127.0.0.1:5984/mydb
also gives unauthorised.

Any ideas anyone?
___________________________________
MacBook Pro, 15" 2.6GHz i7 Mac OS X 10.10.4
iMac 27", 3.2 GHz Quad i7, Mac OS 10.10.4
LiveCode 7.0.6 or 8.0dp4

MaxV
Posts: 1512
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: CouchDB gives me no REST

Post by MaxV » Mon May 15, 2017 1:09 pm

Here some examples:

Code: Select all

put URL "http://127.0.0.1:5984/" into field 1  
#You get: {"couchdb":"Welcome","uuid":"c049bbaa8f32635820f367ec7e77e4b6","version":"1.5.0","vendor":{"version":"14.04","name":"Ubuntu"}}

put URL "http://127.0.0.1:5984/_all_dbs"  
#You get: ["_replicator","_users"]

put shell("curl -X PUT http://127.0.0.1:5984/baseball") into field 1
#You get:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    12  100    12    0     0    215      0 --:--:-- --:--:-- --:--:--   222
{"ok":true}


Moreover you can insert a widget browser and set the URL to "http://127.0.0.1:5984/_utils/" and obtain the database manager.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1512
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: CouchDB gives me no REST

Post by MaxV » Mon May 15, 2017 1:16 pm

This also work:

Code: Select all

PUT empty into url "http://127.0.0.1:5984/plankton"
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

hliljegren
Posts: 107
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: CouchDB gives me no REST

Post by hliljegren » Tue May 16, 2017 8:10 am

MaxV wrote:This also work:

Code: Select all

PUT empty into url "http://127.0.0.1:5984/plankton"
Thanks for all input but the problem is that all of your code above works for me too as long as I have not closed down the database with username and password. When I close it down, the put empty … above will give me an error, even if I submit the username and password. With username / password all HTTP GET works, all HTTP POST works. HTTP PUT works if I insert data into an existing database but put empty to create a new database or HTTP DELETE to remove one doesn't. Calling curl -X PUT with same username and password does work!

But thanks anyway for your effort...
___________________________________
MacBook Pro, 15" 2.6GHz i7 Mac OS X 10.10.4
iMac 27", 3.2 GHz Quad i7, Mac OS 10.10.4
LiveCode 7.0.6 or 8.0dp4

MaxV
Posts: 1512
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: CouchDB gives me no REST

Post by MaxV » Tue May 16, 2017 3:38 pm

It works for me:

Code: Select all

put URL "http://admin:admin@127.0.0.1:5984/plankton"
do you have special chars in your password? Try urlencode function
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

hliljegren
Posts: 107
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: CouchDB gives me no REST

Post by hliljegren » Wed May 17, 2017 12:11 pm

Thanks for your continuing effort. But to be clear:

I can't create a new database as I for that get HTTP/1.1 401 Unauthorized, I can't delete a database. For that I also get HTTP/1.1 401 Unauthorized. Everything else works!
I have no strange characters in the username / password (even tried with test/test with the same results). Using the same username / password via curl works fine so it is not a permission issue.

After further investigation I can see that LiveCode doesn't send the credentials in the HTTP header.
curl -X PUT http://test:test@127.0.0.1/newdb
adds an http header line:

Code: Select all

Authorization: Basic dGVzdDp0ZXN0
But LiveCode does not!

Adding the line manually by:

Code: Select all

set the httpheaders to "Authorization: Basic" && base64encode(tUsername & ":" & tPassword)
makes it work.

So LiveCode isn't submitting the authorization correctly via HTTP(S). Time to bug-report?!
___________________________________
MacBook Pro, 15" 2.6GHz i7 Mac OS X 10.10.4
iMac 27", 3.2 GHz Quad i7, Mac OS 10.10.4
LiveCode 7.0.6 or 8.0dp4

MaxV
Posts: 1512
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: CouchDB gives me no REST

Post by MaxV » Thu May 18, 2017 1:12 am

on my machine a protected database with user and password, it can be accessed using livecode, create database and delete it.

see:

Code: Select all

put url "http://admin:admin@127.0.0.1:5984/_users/_all_docs"
= 
{"total_rows":2,"offset":0,"rows":[
{"id":"_design/_auth","key":"_design/_auth","value":{"rev":"1-619db7ba8551c0de3f3a178775509611"}},
{"id":"org.couchdb.user:admin","key":"org.couchdb.user:admin","value":{"rev":"1-c363450b879aaf64823901816b5690db"}}
]}

put url "http://admin:admin@127.0.0.1:5984/_all_dbs"
= 
["_replicator","_users"] 

put empty into url "http://127.0.0.1:5984/newdb"
put the result
=
error 401 Unauthorized

put empty into url "http://admin:admin@127.0.0.1:5984/newdb"
put url "http://admin:admin@127.0.0.1:5984/_all_dbs"
= 
["_replicator","_users","newdb"]

delete url "http://admin:admin@127.0.0.1:5984/newdb"
put url "http://admin:admin@127.0.0.1:5984/_all_dbs"
= 
["_replicator","_users"] 
It works perfect on my Linux 64bit machine.

Did you use the http://127.0.0.1:5984/_utils/ page to create admin and users? If not, probably you scrambled the user authentication systems. CouchDB is nice, but too experimental too me.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Internet”