I'm having issues getting a rest client written in Node.js to be able to send data (via GET) to a ServiceStack JSON-based Service. It's giving me a serialization error. However, I've copied and pasted the same JSON (generated by my Node.js rest client) into a call to the ServiceStack Service sent via CURL and ServiceStack isn't having an issue with the JSON--again...only as long as it is coming from CURL.
Any pointers or further enlightenment anyone can shed will be much appreciated!
Thanks,
Tami
So I figured out how to get the above working in Node.js and not just in CURL (sending/receiving JSON to a ServiceStack JSON service).
I did the following:
Use the "get()" method of restler...DO NOT USE THE "json()" METHOD
(Code snippet follows...)
var obj = {};
obj.objectName = 'foo';
obj.foos = [{firstname: 'foo1', lastname: 'foo-you'}, {firstname: 'foo2', lastname: 'foo-you-2'}];
var json = JSON.stringify(obj);
var options = {
method: "get",
data: json,
headers: {'Content-type': 'application/json', 'Accept': 'application/json'}
};
rest.get('http://localhost/servicestack-api/getmethod', options).
on('complete', function(data, response){
console.log(data);
console.log(response.statusCode);
});
Make sure to fill in the above with the correct url and remote DTO to your ServiceStack service and method
FYI
If your json does not serialize to the remote DTO in ServiceStack, a quick way to test would be to copy and paste the json stored in the "json" variable above into a curl command to see if it serializes correctly that way.
(Sample curl snippet below...)
This is what I did initially (see original question) to try to trouble-shoot serialization issues. It helped me isolate the problem to the restler/Node.js side so I could make the modifications you see above--namely NOT using the "json()" method of restler.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X GET -d '{"foos":[{"firstname":"foo1","lastname":"foo-you"}, {"firstname": "foo2", "lastname": "foo-you-2"}],"objectName": "foo"}' http://localhost/servicestack-api/getmethod