PDA

View Full Version : How to override REST endpoints?



wardrop
15 Jul 2013, 5:56 PM
Hi,

I understand that one can override the endpoints for the REST proxy using the `api` configuration property. However, I still have a couple questions. Firstly, is there anyway I can tell ExtJS where to insert variables in those URL's, such as the ID? If I had an endpoint like this for example
/person?id=1, how would I tell ExtJS to use that instead of
/person/1 for example?

Also, is there anyway to allow say read and update, but not provide any methods for creating or removing records. How do I configure my REST proxy in that scenario?

Cheers,
Tom

wardrop
15 Jul 2013, 7:39 PM
I have another question. Some of the things I'll be doing will not match the CRUD model, and so there will be instances where I'll just have to send bespoke requests to the server. Can someone point at the relevant documentation for issuing generic asynchronous requests with Ext JS?

slemmon
17 Jul 2013, 1:02 PM
You could extend the Rest proxy and do your own implementation of the buildUrl method which is used to construct the URL used when communicating via the Rest transactions:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Rest-method-buildUrl

Instead of setting a URL on the proxy's url config you can specify an api config and set the url for just the read and update actions (though I'd think that ultimately prohibiting destroy and create actions would fall more to UI design):
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Rest-cfg-api

For ad hoc transactions you can use Ext.Ajax.request().
You can pass a config as a param to request() including method which will allow you to specify the verb to use (POST, GET, PUT, etc.)
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Ajax-method-request

okwei
17 Jul 2013, 1:48 PM
http://www.sencha.com/forum/showthread.php?268094-Rest-Proxy-and-Different-Roots-for-Different-Operations-(List-Create)-autoSync

skirtle
17 Jul 2013, 7:57 PM
The basics of writing a custom proxy:

http://skirtlesden.com/articles/custom-proxies

I'd also advise reading the source code for Rest proxy, there's not a lot to it.

Jarrod Roberson
16 Jan 2018, 9:29 AM
I'd also advise reading the source code for Rest proxy, there's not a lot to it.

Where is the source code found?

I have the commercial SDK and I can not find the source for the REST proxy anywhere.