Sencha Touch - RESTful load() specific instance URL problem (Store/model) - sencha-touch

It seems there is a problem with loading a specific instance (load() function) using the rest proxy in a model/store object. example:
Code:
Ext.regModel('User', {
fields: ['id', 'name', 'email'],
proxy: {
type: 'rest',
url : '/users'
}
});
//get a reference to the User model class
var User = Ext.ModelMgr.getModel('User');
//Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
success: function(user) {
console.log(user.getId()); //logs 123
}
});
This code is copied from Sencha touch's API. the generated URL is http://localhost/users?_dc=... instead of the desired (and documented) url http://localhost/users/123.
it also happens when using the store.load with a parameter.
Am I doing something wrong here?
Thanks
T

It seams the id parameter has been documented but not implemented. This has been discussed in the sencha forum [link]. A few non complete fixes are written in post #8 and post #13.

Related

How to show input and output exemple with nelmio-api-bundle and php8.1

I'm currently trying to make an API doc page thanks to nelmio-api-bundle. I only have one route which is a POST route. I'm receiving a JSON in the body of the request and I'm using the Serializer from symfony to deserialize it in a DTO. I'm also using a DTO for the response (which contains the status code, a bool set to true or false, and a message). Now I'm trying to use these DTO (for input and output) to build the API documentation with nelmio-api-bundle but how to make it ? I'm using PHP8.1 attributes to make it, for response it almost works (except that the response is shows as an array) but I don't know how to make it for the inputs.
Here is my current code:
#[Route('/user', methods: ['POST'])]
#[OA\Parameter(
name: 'user',
description: 'The user information in JSON',
in: 'query',
required: true
)]
#[OA\Response(
response: 200,
description: 'Returns the success response',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: new Model(type: SuccessResponseDTO::class))
)
)]
public function registerUser(Request $request, LoggerInterface $logger): JsonResponse
{
//the code to register the user
}
And here is the result:
Do someone know how to make it ?

JayData oData request with custom headers

I need to send custom headers to my wcf oData Service but with the following function the headers dont get modified.
entities.onReady(function () {
entities.prepareRequest = function(r) {
r[0].headers['APIKey'] = 'ABC';
};
entities.DataServiceClient.toArray(function (cli) {
cli.forEach(function (c) {
console.log(c.Name)
});
});
});
headers are not affected. any clue?
thanks!
It seems that the marked answer is incorrect. I was suffering from a similar issue, but got it working without changing datajs.
My issue was that I was doing a cross domain (CORS) request, but didn't explicitly allow the headers. After I added the correct CORS header to the webservice, it worked.
EDIT
On second thought, it seems like there is still something broken in JayData for MERGE requests.
This is NOT CORS and has nothing to do with it!
see JayData oData request with custom headers - ROUND 2
the bellow "hack" works, but the above question should take this problem to a new level.
----------
Old answer
Nevermind I found a solution.
It seems like prepareRequest is broken in JayData 1.3.2 (ODataProvider).
As a hack, I added an extraHeaders object in the providerConfiguration (oDataProvider.js):
this.providerConfiguration = $data.typeSystem.extend({
//Leave content unchanged and add the following:
extraHeaders: {}
}, cfg);
then at line 865 modify requestData like this:
var requestData = [
{
requestUri: this.providerConfiguration.oDataServiceHost + sql.queryText,
method: sql.method,
data: sql.postData,
headers: _.extend({
MaxDataServiceVersion: this.providerConfiguration.maxDataServiceVersion
},this.providerConfiguration.extraHeaders)
},
NOTE: Iam using lodash for conveniance, any js extend should do the trick.
then you just create your client like this:
var entities = new Entities.MyEntities({
name: 'oData',
oDataServiceHost: 'http://myhost.com/DataService.svc',
maxDataServiceVersion: "2.0",
//enableJSONP: true,
extraHeaders: {apikey:'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5', Accept:'application/json;odata=verbose'}
}
);

How to use an API

I'm studying Informatics but somehow I don't get that one.
I want to set up the PayPal NVP-API.
(NVP = Name value Pair).
Can someone tell me how I can CALL an API-Command?
I don't even know which programming language I have to take :S
Reference to the Tutorial: PayPal NVPAPI Developer Guide
It sounds like you might be a bit over your head on this one, but don't worry it's not that difficult.
When they say POST they literally mean an HTTP POST, but since its SSL you'd need to provide credentials also.
jQuery AJAX http://api.jquery.com/jQuery.ajax/ would be a good place to start..
$.ajax({
url : 'paypalurl',
type : 'POST', //IMPORTANT
username : 'username',
password : 'password',
data : 'YOUR DATA HERE' //form or something of the like
success : function(r) {
//handle the success here
},
error : function(e) {
//uh-oh
}
});
This should get you started, but please be careful this is financial data.

Sencha touch 2 - show response (JSON string) on proxy loading

Is there a way to output the json-string read by my store in sencha touch 2?
My store is not reading the records so I'm trying to see where went wrong.
My store is defined as follows:
Ext.define("NotesApp.store.Online", {
extend: "Ext.data.Store",
config: {
model: 'NotesApp.model.Note',
storeId: 'Online',
proxy: {
type: 'jsonp',
url: 'http://xxxxxx.com/qa.php',
reader: {
type: 'json',
rootProperty: 'results'
}
},
autoLoad: false,
listeners: {
load: function() {
console.log("updating");
// Clear proxy from offline store
Ext.getStore('Notes').getProxy().clear();
console.log("updating1");
// Loop through records and fill the offline store
this.each(function(record) {
console.log("updating2");
Ext.getStore('Notes').add(record.data);
});
// Sync the offline store
Ext.getStore('Notes').sync();
console.log("updating3");
// Remove data from online store
this.removeAll();
console.log("updated");
}
},
fields: [
{
name: 'id'
},
{
name: 'dateCreated'
},
{
name: 'question'
},
{
name: 'answer'
},
{
name: 'type'
},
{
name: 'author'
}
]
}
});
you may get all the data returned by the server through the proxy, like this:
store.getProxy().getReader().rawData
You can get all the data (javascript objects) returned by the server through the proxy as lasaro suggests:
store.getProxy().getReader().rawData
To get the JSON string of the raw data (the reader should be a JSON reader) you can do:
Ext.encode(store.getProxy().getReader().rawData)
//or if you don't like 'shorthands':
Ext.JSON.encode(store.getProxy().getReader().rawData)
You can also get it by handling the store load event:
// add this in the store config
listeners: {
load: function(store, records, successful, operation, eOpts) {
operation.getResponse().responseText
}
}
As far as I know, there's no way to explicitly observe your response results if you are using a configured proxy (It's obviously easy if you manually send a Ext.Ajax.request or Ext.JsonP.request).
However, you can still watch your results from your browser's developer tools.
For Google Chrome:
When you start your application and assume that your request is completed. Switch to Network tab. The hightlighted link on the left-side panel is the API url from which I fetched data. And on the right panel, choose Response. The response result will appear there. If you have nothing, it's likely that you've triggered a bad request.
Hope this helps.
Your response json should be in following format in Ajax request
{results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]}
id and name are properties of your model NOte.
For jsonp,
in your server side, get value from 'callback'. that value contains a name of callback method. Then concat that method name to your result string and write the response.
Then the json string should be in following format
callbackmethod({results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]});

Random numbers added to extjs data store ajax call

var resource_store = Ext.create('Ext.data.Store', {
pageSize: 10,
autoLoad: true,
fields: ['id','r_number','c_number','resource_name','resource_desc','resource_url','resource_file'],
proxy: {
type: 'ajax',
url: BASE_URL+'courses/resources/displayResources/'+course_id,
reader: {
type: 'json',
root: 'results'
}
},
storeId: 'id'
});
I'm using Extjs4 data store like this way.
When i see the ajax calls a random number is appended to the url
http://localhost/Edu_web/index.php/courses/resources/displayResources/PTGRE14?_dc=1328442262503&page=1&start=0&limit=10
Even though i use
actionMethod:{
read: 'POST'
}.
?_dc=1328442262503 still appears in the url.
how to remove these parameters in url. and send any parameters through POST
Even though i use actionMethod:{ read: 'POST' }.
?_dc=1328442262503 still appears in the url.
Of course it would. You should use actionMethods (with 's' at the end).
To remove _dc from GET request you should add noCache: false to proxy's config. Docs for noCache.
P.S. Using a POST for reading is a bad practise. You should only use a POST when you are modifying data on the server.
If there are any proxy in your network, before disabling the random number, check to see if they have caching disabled, otherwise the client, instead of downloading the updated pages from the server, will continue to read the previous ones stored in the proxy. The random number added to the call makes it different each time and the proxy will be forced to always download it from the server