Coax/Hoax and PhoneGap

210 views
Skip to first unread message

stefan...@gmail.com

unread,
Feb 14, 2014, 11:48:48 AM2/14/14
to mobile-c...@googlegroups.com


Hi everybody,

I have a general problem with coax/hoax to define URI's with query parameters like "http://myurl.com/test?query=param".
I found coax and hoax in the Couchbase-Light example PhoneGap APP "TodoLite-PhoneGap".

I definitely need query params, because I want to DELETE couchbase documents or even updating them,
Therefore the revision is required as query parameter (to name just one scenario).

I tested this:

var server = hoax("http://myserver.com/");
var options = {
   uri: 'test',
   qs: {
      mykey: 'myvalue'
   }
};

var path = server(options);

path.get("123", function(err, json){
    console.log("put json", json);
});

The request is sent, but the query parameter is just ignored.
Even the official hoax example does not fire query parameters: https://github.com/jchris/hoax

Whats wrong? Any suggestions?

Would be fantastic if Chris Anderson reads this post ;-)

Cheers and thanks,
Stefan

Traun Leyden

unread,
Feb 14, 2014, 1:38:38 PM2/14/14
to mobile-c...@googlegroups.com

What about:

var path = server(options, {mykey: "myvalue"});

Does that work?




--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/d1c9366c-d78b-4fd2-a092-dc2a2e608a04%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

J. Chris Anderson

unread,
Feb 14, 2014, 1:49:58 PM2/14/14
to mobile-c...@googlegroups.com


On Friday, February 14, 2014 8:48:48 AM UTC-8, stefan...@gmail.com wrote:


Hi everybody,

I have a general problem with coax/hoax to define URI's with query parameters like "http://myurl.com/test?query=param".
I found coax and hoax in the Couchbase-Light example PhoneGap APP "TodoLite-PhoneGap".

I definitely need query params, because I want to DELETE couchbase documents or even updating them,
Therefore the revision is required as query parameter (to name just one scenario).

You are almost there. Coax is mostly a URL-path currying API with a little bit of knowledge about changes feed etc. So for your use case you want to do something like this:

var server = coax("http://server.com")

// just for example
var database = server("my-database")


database.get(function(error, data){
   // did a get to http://server.com/my-database
})

database.get("foobar", function(error, data){
})

// note the array
database.get(["foobar", "baz"], function(error, data){
})

// still an array, with query options
database.get(["foobar", "baz", {"x" : "y"}], function(error, data){
})

It looks like the uri and qs parameters you are using are the API to mikeal's request library, which hoax uses, but doesn't share the same API.

Hope that helps!

Chris

stefan...@gmail.com

unread,
Feb 14, 2014, 2:46:04 PM2/14/14
to mobile-c...@googlegroups.com
Brilliant answer, Chris - thanks a lot!

I think it would be really helpful if you put this short example on the github readme.md.

Cheers,
Stefan
Reply all
Reply to author
Forward
0 new messages