PDA

View Full Version : How replace Ajax URI parameters with REST path?



simonr25
8 Jan 2014, 2:30 AM
Hello,

The code below is an example of an Ajax request from some code I am maintaining.
When the request is invoked, this leads to the following URL being sent -
which includes parameters:

http://{server}/{app}/getOrder?id={par}

Instead of using parameters I would like to use path variables and a REST
URI format,
i.e.

http://{server}/{app}/order/{par}

Please can you inform me how I can modify the Ajax request or else replace
it to handle REST formats.

I have observed the REST proxy but not a REST request.

Also the Ajax request does not have put or delete methods - how do I handle
these?

Are the REST requests asynchronous?



var par= rec.get('id');

Ext.Ajax.request({
url: 'app/getOrder',
method: 'get',
params: {
id: par
}
success: function(response){
...
}
failure: function(response){
...
}
});


regards,
S

scottmartin
8 Jan 2014, 3:38 PM
Perhaps this may interest you:
https://market.sencha.com/extensions/ext-ux-router

skirtle
9 Jan 2014, 4:36 AM
Isn't it just this?


Ext.Ajax.request({
url: 'app/order/' + par,
method: 'DELETE',

...
});

simonr25
9 Jan 2014, 7:42 AM
Thank you for responses.

Can the Ajax request take method type 'DELETE'?

From the API documentation, it says that method type is either get or post?

kind regards,
Simon

skirtle
9 Jan 2014, 12:27 PM
I'm not sure where you're reading that. The docs I'm looking at discuss the default value being GET or POST but I don't see anywhere that it says those are the only allowed values.

existdissolve
9 Jan 2014, 4:50 PM
Hello,

The code below is an example of an Ajax request from some code I am maintaining.
When the request is invoked, this leads to the following URL being sent -
which includes parameters:

http://{server}/{app}/getOrder?id={par}

Instead of using parameters I would like to use path variables and a REST
URI format,
i.e.

http://{server}/{app}/order/{par}

Please can you inform me how I can modify the Ajax request or else replace
it to handle REST formats.

I have observed the REST proxy but not a REST request.

Also the Ajax request does not have put or delete methods - how do I handle
these?

Are the REST requests asynchronous?



var par= rec.get('id');

Ext.Ajax.request({
url: 'app/getOrder',
method: 'get',
params: {
id: par
}
success: function(response){
...
}
failure: function(response){
...
}
});


regards,
S

The important thing to understand is that there is nothing special about "REST" in terms of requests. REST is not a "type" of request at all, but is only a design pattern. Whether you are creating RESTful URLs or something else, you are still making HTTP requests.