Page 1 of 2

How to get server code to post or put to couchdb?

Posted: Fri Jul 25, 2014 1:54 am
by Esau Romano

self explanatory

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
var XHRResponse = XHR.send("PUT", "http://username:password@ipaddress/te...", {
headers:{
'Content-Type':'application/json',
'accept':'application/json'
},
data:{
"Subject":"I like Plankton",
"Author":"Rusty",
"PostedDate":"2006-08-15T17:30:12-04:00",
"Tags":["plankton", "baseball", "decisions"],
"Body":"I decided today that I don't like baseball. I like plankton."
}
});
responseBody.requestBody = request.body();
responseBody.requestParams = requestParams;
console.log(XHRResponse.body);
response.success(XHRResponse.body, "application/json");


How to get server code to post or put to couchdb?

Posted: Fri Jul 25, 2014 3:59 am
by Yurii Orishchuk

Hi Esau,

Looks okay,

Do you have some problem with this request?

Regards.


How to get server code to post or put to couchdb?

Posted: Fri Jul 25, 2014 1:26 pm
by Maryna Brodina

Hello Esau!

Just to add - here is how to send requests from servercode using XMLHttpRequest http://devcenter.appery.io/documentat.... Here is an API description http://docs.couchdb.org/en/latest/int...


How to get server code to post or put to couchdb?

Posted: Sat Jul 26, 2014 1:39 am
by Esau Romano

Hello Yurii and Maryna

Your examples in the tutorial only includes, GET, while im in the urgency to use POST and PUT verbes, please elaborate on your answer and, if posible, please translate this curl commands to individual scripts i can use on the script platform.

curl -X PUT http://127.0.0.1:5984/albums/6e1295ed... -d '{"title":"There is Nothing Left to Lose","artist":"Foo Fighters"}'

curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed... \
--data-binary @artwork.jpg -H "Content-Type:image/jpg"

curl -vX POST http://127.0.0.1:5984/_replicate \
-d '{"source":"albums","target":"http://example.org:5984/albums-replica"}' \
-H "Content-Type:application/json"


How to get server code to post or put to couchdb?

Posted: Mon Jul 28, 2014 2:40 pm
by Maryna Brodina

Hello!

Here is an example how would your first request look like:

prevar XHRResponse = XHR&#46;send("GET", "http:&#47;&#47;127&#46;0&#46;0&#46;1:5984/albums/6e1295ed6c29495e54cc05947f18c8af", {"title":"There is Nothing Left to Lose","artist":"Foo Fighters"});
result = "status: " + XHRResponse&#46;status;
result += "body: " + XHRResponse&#46;body;
response&#46;success(result, "text/plain");/prePlease note 127.0.0.1 is a localhost, not real address. You need to replace it with real one.


How to get server code to post or put to couchdb?

Posted: Mon Jul 28, 2014 5:23 pm
by Esau Romano

THIS DOES NOT RUN AND IS NOT A POST, PLEASE BE SO GENTLE TO GIVE A CORRECT EXAMPLE

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
var XHRResponse = XHR.send("GET", "http://USER:PASSWORD@IPADDRESS/prueba...", {"title":"There is Nothing Left to Lose","artist":"Foo Fighters"});
result = "status: " + XHRResponse.status;
result += "body: " + XHRResponse.body;
response.success(result, "text/plain");

IT GIVES ME THIS

Script genericpost: Error: NullPointerException ( @ 8 : 45 ) - var innerResult = GlobalXHRInner.send(method, url, GlobalJSON.stri


How to get server code to post or put to couchdb?

Posted: Tue Jul 29, 2014 7:14 pm
by Kateryna Grynko

Hi Esau,

This is an incorrect URL:
"http://USER:PASSWORD@ipaddress/prueba..."

Please use the following:
"http://example.com/param1/param2"


How to get server code to post or put to couchdb?

Posted: Wed Jul 30, 2014 1:36 am
by Esau Romano

but, how do i read the params and send them as user and password?


How to get server code to post or put to couchdb?

Posted: Wed Jul 30, 2014 5:37 am
by Evgene Karachevtsev

Hello Esau,

Sorry for misunderstanding. This is the normal URL. The third parameter of the send method is not set correctly.
PLease look here to see its structure: http://devcenter.appery.io/documentat...
For example, the right structure looks like:
prevar XHRResponse = XHR&#46;send("POST", "http:&#47;&#47;USER:PASSWORD@ipaddress/prueba/okok", {
"body": {
"source": "albums",
"target": "http:&#47;&#47;example&#46;org:5984/albums-replica"
},
"headers": {
"Content-Type": "application/json"
}
});/pre


How to get server code to post or put to couchdb?

Posted: Thu Jul 31, 2014 1:59 am
by Esau Romano

Evgene, you are the man!, that was it!, now everything someone could need to control couchdb api from appery.io's server code is in this post, i can even write a tutorial if you like