0
votes

i use reste library to handle api on titanium appcelerator :

this is my config :

api.config({
        debug : true,
        autoValidateParams : false,
        validatesSecureCertificate : false,
        timeout : 4000,
        url : Kb.baseUrl,
        models: [{
            name: "product",
            id: "id",
            //content: "retArray",
            collections: [{
                name: "products",
                content: "response",
                read: "get_products"
            }],
        }],
        methods : [
            {
                name : "get_products",
                post : "api/get_product"
            }
        ],
...

So this how i fetch (works perfectly) :

var p = Alloy.Collections.get_products;
p.fetch({
    success:function(m,r){
        console.log(r)
    }
});

Now i have to past object to post (this not working, why?) :

p.fetch({
    data:{'id':'2'},
    success:function(m,r){ console.log(r); }
});

This second fetch not working, have you an idea ?

thanks.

1

1 Answers

0
votes

In your config you're not specifying what to do with the id parameter. RESTe doesn't know (or care) about your API -- i.e if it's REST / PUT, GET based or POST, GET etc. So you need to tell it.

Change your method to:

{
  name : "get_products",
  post : "api/get_product/<id>"
}

and it should work fine. The flexibility here allows RESTe to work with APIs that don't conform to the normal REST pattern so if it required say:

"api/get_product?id=<id>"

for example.