I am trying to access a REST service using extjs proxy rest, but the url that is being sent looks weird, take a look:
/rest/v1/distribution-list/1*?id=1*
I dont know why 'id' is being sent.
It shoul send '/rest/v1/distribution-list/1'
Any ideas?
this is my model
Ext.define('Wave.model.DistributionList', {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'name', type: 'string'},
{name: 'status', type: 'string'}
],
proxy: {
type: 'rest',
noCache: false,
reader: {
type: 'json'
},
writer: {
type: 'json'
},
actionMethods: {
create: 'POST',
read: 'GET', // defaults to GET
update: 'POST',
destroy: 'DELETE'
},
api: {
read: '/rest/v1/distribution-list/',
create: '/rest/v1/distribution-list/',
update: '/rest/v1/distribution-list/',
destroy: '/rest/v1/distribution-list/'
}
}
});
Cheers
-Henrique
the ID have been send is setted by Extjs.you can change that using the idParam to changed to other one;
Working with sencha-touch 2.3.1 and rest proxy, ExtJS creates the URL to the action methods with query string parameters, like you said: /rest/v1/distribution-list/?id=1.
If you don't want to append the id, you can change appendId to false inside proxy config.
Related
on mongo db compass I'd like to use a validation schema but on of my properties is an enum, depending on this field another field can be toggled I was able to do this using JSON schema but it dosen't seems to be working on mongoDB compass why ?
{
type: 'object',
properties: {
type: {
enum: ['teacher', 'student']
},
firstname: {
type: 'string',
},
lastname: {
type: 'string',
},
login: {
type: 'string',
},
pwd: {
type: 'string'
},
"if": {"properties": {"type": {"const": "student"}}},
"then": {"properties": {classes: {type: "array"}}}
},
required: [
'type',
'firstname',
'lastname',
'login',
'pwd',
],
};
No.
The MongoDB documentation indicates that it is using draft 4:
JSON Schema object is formatted according to draft 4 of the JSON Schema standard.
The JSON Schema site says these conditionals are new in draft 7:
New in draft 7 if, then and else keywords
let validator = new Validator(req.body, {
password: "requiredIf:is_login_user,1",
});
I have an association between Client and Budget as follows:
//Client.js
module.exports = {
primaryKey: 'id',
attributes: {
id: {
type: 'number',
unique: true,
autoIncrement: true
},
name: {
type: 'string'
},
phone: {
type: 'string',
unique: true
},
email: {
type: 'string',
unique: true
},
budgets: {
collection: 'budget',
via: 'client'
},
}
};
// Budget.js
module.exports = {
primaryKey: 'id',
attributes: {
id: {
type: 'number',
unique: true,
autoIncrement: true
},
client: {
model: 'client'
},
budgetItems: {
type: 'json'
}
}
};
So, POST is working for both entities so I can create both of them, but:
GET /budget/1
returns the budget and the id of the associated client.
GET /budget/1/client
returns the client id without populating(as i've seen in documentation it should be populated).
GET /client/1
returns the client attributes and there is not a field related with budgets.
GET /client/1/budgets
returns 404 NOT FOUND
I'm following this and this official documentation
So what I could be missing?
Is just generating one direction associations, and I've compared with official documentation and third party examples and my code looks fine.
Thanks in advance!
Update:
I still looking for troubles and if I run sails with --silly option it shows there is the following route available:
Binding route :: get /client/:parentid/budgets POLICY: localize
Binding route :: get /client/:parentid/budgets POLICY: isauth
Binding route :: get /client/:parentid/budgets BLUEPRINT: populate
but if I try to access returns a 404 Not Found and console shows the following error, thrown by populate.js from Sails core code:
verbo: In populate blueprint action: Specified parent record (1)
does not have a budgets.
Update2:
Debugging with sails console I've seen the association is generated properly. Given Client.findOne({id: 1}).populate('budgets').then((client)=>{console.log(client)}) print the client attributes and the associated Budgets but still return 404 Not Found when: GET /client/1/budgets
I have created quick demo and it seems working fine for me.
For demo I have used sails version 1.2.2 and sails-disk as database and there is some minor difference in Model attributes as below
Client.js
module.exports = {
attributes: {
name: {
type: 'string'
},
phone: {
type: 'string',
unique: true,
required: true
},
email: {
type: 'string',
unique: true,
required: true
},
budgets: {
collection: 'Budget', // <<== B is capital here
via: 'client'
},
},
};
Budget.js
module.exports = {
attributes: {
client: {
model: 'Client' // <<== C is capital here
},
budgetItems: {
type: 'json'
}
},
};
Let me know if this is helpful
thanks to SailsJS team we've found the problem and it was related with a third party package and just had to remove it from my project.
It was sails-hook-deep-orm who's owner has been warned. I hope someone with the same issue will reach this post.
Thanks u all anyway!!
The issue is available there
I am using Rest proxy in Extjs Model as:
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model', fields: [
{ name: 'userId' },
{ name: 'title' },
{ name: 'body'}
],
proxy: {
type: 'rest',
format: 'json',
limitParam:"",
filterParam: "",
startParam:'',
pageParam:'',
url:'http://jsonplaceholder.typicode.com/posts/1',
api: {
read : 'http://jsonplaceholder.typicode.com/posts/1',
create: 'http://httpbin.org/post'},
headers: {'Content-Type': "application/json" },
reader: {
type: 'json',
//rootProperty:'issues'
},
writer: {
type: 'json'
}
In my view I am calling create function as:
var user = Ext.create('posts', {"userId": 124,"title": "sunt","body": "quia"});
user.save();
As I am testing everything on http://jsonplaceholder.typicode.com/ so I am expecting that code will work cause when I test GET and POST functionality via Postman utility everything works fine.
Can anyone point out my error?
I found my mistake.
In the following code I was not setting the correct name of my model, as it won't be "Posts"
var user = Ext.create('posts', {"userId": 124,"title": "sunt","body": "quia"});
user.save();
Also if you are trying with http://jsonplaceholder.typicode.com/ you are not supposed to send ID in the post request.
I'm trying to connect a REST API to my ExtJS application.
For GET /user alike requests I return a response as follows:
{items: [{id: 1, ...}, {id: 2, ....}], total: 2}
So I created a model for that:
Ext.define('model.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name' },
],
proxy: {
reader: {
type: 'json',
totalProperty: 'total',
rootProperty: 'items'
},
type: 'rest',
url: '/Api/User',
}
});
The grids load data and all look perfect. Now I want to be able to request a single record which my api serves as {id: 1, ...}.
But when I do model.User.load(1) the success handler is never triggered because the response doesn't contain items property. If I put my record in that property, it will work but also will look ugly for other API users.
How can I make it work without the root property? I can't find any events for proxy/reader on a model to change it dynamically.
The rootProperty can also be a function, so you could do something like:
rootProperty: function(raw) {
return raw.items ? raw.items : raw;
}
I'm trying to use the 'rest' proxy with extjs to connect to my delphi xe2 rest server.
This does a request and works when I use jsonp
proxy: {
type: 'jsonp',
api: {
create: {url:"http://10.0.29.64:8080/datasnap/rest/tsmbank/client", method:"PUT"},
read: "http://10.0.29.64:8080/datasnap/rest/tsmbank/client",
update: {url:"http://10.0.29.64:8080/datasnap/rest/tsmbank/client", method:"POST"},
destroy: {url:"http://10.0.29.64:8080/datasnap/rest/tsmbank/Client", method:"DELETE"}
},
callbackKey: 'theCallbackFunction',
reader: {
type: 'json',
root: 'allclients',
totalProperty: 'totalCount'
},
writer: new Ext.data.JsonWriter({
//type: 'json',
writeAllFields: true
})
}
But if I try to use the Restproxy type it sends an "OPTIONS" method
proxy: {
type: 'rest',
url: "http://10.0.29.64:8080/datasnap/rest/tsmbank/client",
callbackKey: 'theCallbackFunction',
reader: {
type: 'json',
root: 'allclients',
totalProperty: 'totalCount'
},
writer: new Ext.data.JsonWriter({
//type: 'json',
writeAllFields:true
})
}
Or I guess the other quetions is how to handle the "OPTIONS" request method with a delphi rest server?