please provide any code or any example or any link.
vm.dtOptions = DTOptionsBuilder.fromSource( baseApi + '/NH/dashboard' ).withFnServerParams( serverParams );
function serverParams ( aoData ) {
aoData.push( jsonObj );
}
it gives error..
DTOptionsBuilder.fromSource(...).withFnServerParams is not a function
Related
I am trying to do a REST client using AS3, I am following this tutorial: http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b061afd5d7127074bbf44-8000.html
My code is the following:
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
var url:String = "https://localhost:8443/restcomponent/tesimalex";
var requestor:URLLoader = new URLLoader();
function restServiceCall():void
{
trace("Calling REST Service...");
//Create the HTTP request object
var request:URLRequest = new URLRequest( url );
request.method = URLRequestMethod.GET;
//Add the URL variables
// var variables:URLVariables = new URLVariables();
// variables.method = "test.echo";
// variables.api_key = "123456ABC";
// variables.message = "Able was I, ere I saw Elba.";
// request.data = variables;
//Initiate the transaction
requestor = new URLLoader();
requestor.addEventListener( Event.COMPLETE, httpRequestComplete );
requestor.addEventListener( IOErrorEvent.IO_ERROR, httpRequestError );
requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpRequestError );
requestor.load( request );
}
function httpRequestComplete( event:Event ):void
{
trace( event.target.data );
}
function httpRequestError( error:ErrorEvent ):void{
trace( "An error occured: " + error.toString() );
}
The only diference between my code and the one in the tutorial is the URL variables, that I commented, and the url used.
My REST service is a simple GET, if I type the url in the browser it shows me the JSON returned.
But in my AS3, when I call the method restServiceCall() it returns the following error:
Error opening URL 'https://localhost:8443/restcomponent/tesimalex?' An
error occured: [IOErrorEvent type="ioError" bubbles=false
cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL:
https://localhost:8443/restcomponent/tesimalex?"]
Anyone knows whats wrong?
Ok... It was a security issue... I disabled SSL in my server and then my flash app managed to comunicate with my REST service.
I'm building a small app that consumes a REST service.
The REST service expects that the URL i interact with always have the API key as an URL parameter.
So no matter if i GET, POST, UPDATE or DELETE, my URL should always contain be something like this:
https://rest.service.tld:443/list?api_key=MY-KEY
https://rest.service.tld:443/lists/1/profiles/search?api_key=MY-KEY
I tried with the sample code from RestSharp webpage, but it get the statuscode Access Denied
Here's my code:
// Create client
var client = new RestClient( "https://rest.service.tld:443" );
client.Authenticator = new SimpleAuthenticator( "api_key", "MY-KEY", "", "" );
// GET list of items
var requestLists = new RestRequest( "lists", Method.GET );
IRestResponse<List<ListResponse>> listResponse = client.Execute<List<ListResponse>>( requestLists ); // Returns the correct list
// POST search
var requestProfiles = new RestRequest( "lists/1/profiles/search", Method.POST );
requestProfiles.AddParameter( "Criteria", "{\"email\":\my#email.tld\"}" );
IRestResponse profileResponse = client.Execute( requestProfiles ); // Returns 'Access Denied' status code
As far as i can tell, the POST method doesn't contain the correct querystring, instead my api_key is added as a parameter in the POST.
Is there a way to keep my API_KEY in the Querystring like i need it to be?
By default the api_key is added as a normal parameter, you need to explicitly enforce that you want the parameter to be embedded into the URL, by setting the ParameterType as follows:
var requestProfiles = new RestRequest( "lists/1/profiles/search{api_key}", Method.POST );
requestProfiles.AddParameter( "Criteria", "{\"email\":\my#email.tld\"}" );
requestProfiles.AddParameter( "api_key", MY-KEY, ParameterType.UrlSegment);
More info here
I'm new to Sails and I'm trying to figure out the best/proper method for returning a standard object for every API response.
The container our front-end requires is:
{
"success": true/false,
"session": true/false,
"errors": [],
"payload": []
}
Currently, I’m overwriting the blueprint actions in each controller like this example (which just seems so very, very wrong):
find : function( req, res ){
var id = req.param( 'id' );
Foo.findOne( { id : id } ).exec( function( err, aFoo ){
res.json(
AppSvc.jsonReply(
req,
[],
aFoo
), 200
);
});
}
And in AppSvc.js:
jsonReply : function( req, errors, data ){
return {
success : ( errors && errors.length ? false : true ),
session : ( req.session.authenticated === true ),
errors : ( errors && errors.length ? errors : [] ),
payload : ( data ? data : [] )
};
}
Additionally, I’ve had to modify each res.json() method for each default response (badRequest, notFound,etc). Again, this feels so wrong.
So, how do I properly funnel all API responses into a standard container?
Sails custom responses are great for this.
If you look at the blueprint code, you'll see that each one calls res.ok when it's done: https://github.com/balderdashy/sails/blob/master/lib/hooks/blueprints/actions/find.js#L63
You can add your own file - ok.js - to api/responses/ - which will override the default built in handler.
https://github.com/balderdashy/sails/blob/master/lib/hooks/responses/defaults/ok.js <- just copy and paste this to start, and adapt as you need.
I have a node.js program that I am trying to work with the googleapis module (https://github.com/google/google-api-nodejs-client) version 0.2.5-alpha.
I can make calls using the raw HTTP without problems, so I know I am white listed for the API, I am authenticating and authorizing correctly, and the correct scopes and everything are being requested. If I use the same access_token to do an insert into the timeline, I am getting an error in the callback. I am also discovering the plus API, and calls using this API are working fine.
Code fragment to discover the API, which appears to work without problems:
var client;
googleapis
.discover( 'plus', 'v1' )
.discover( 'mirror', 'v1' )
.execute( function(err,data){
console.log( err );
client = data;
});
Code fragment to do the call:
client.mirror.timeline.insert({
text: "test 1 "
} ).withAuthClient(user.auth).execute(function(err,result,res){
console.log( '++ start ++' );
console.log( '+err ', err );
console.log( '+result', result );
//console.log( '+res ', res );
console.log( '++ end ++' );
});
What is logged during the callback:
++ start ++
+err { code: 400,
message: 'Required',
data: [ { domain: 'global', reason: 'required', message: 'Required' } ] }
+result undefined
++ end ++
Any indication what is "Required", how to provide it, or how to further debug errors such as this?
UPDATE: the resource property is no longer required so the original code should just work instead of the proposed solution.
Since the node.js client library is based on the JavaScript client library, you need to set the request body in the "resource" property:
client.mirror.timeline.insert({resource: {
text: "test 1 "
}}).withAuthClient(user.auth).execute(function(err,result,res){
console.log( '++ start ++' );
console.log( '+err ', err );
console.log( '+result', result );
//console.log( '+res ', res );
console.log( '++ end ++' );
});
I am call web-service and I am getting 0 bytes in response as well as getting error like below:
Error Domain=kCFErrorDomainCFNetwork Code=303 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)" UserInfo=0xa9b8ef0 {NSErrorFailingURLKey=http://quantuminfoways.com/crossfit_wodgenius/webservice/sync.php, NSErrorFailingURLStringKey=http://quantuminfoways.com/crossfit_wodgenius/webservice/sync.php}
And i am passing data as the
sample link.
And in data i am passing this:
{
createwod = {
deletedcreatewod = (
);
newcreatewod = (
);
};
favorite = {
deletedfavorite = (
);
newfavorite = (
);
};
gym = {
deletedgym = (
);
newgym = (
);
};
workoutlog = {
deletedworkoutlog = (
);
deletedworkoutlogtime = (
);
newworkoutlog = (
);
};
}
Can any one help me to solve it?
thanks
One of the reason of error "kcferrordomaincfnetwork error 303" when you are calling a POST method as GET.
A 303 error is a redirect error.
You might want to check out the automatic handling of redirects with NSURLConnection:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/RequestChanges.html
If you'd like to handle it manually, the redirect url is in the response's 'Location' header. Here's how you can grab it in your connection:didReceiveResponse delegate method.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
// ... if the response status is 303 ...
if ([response respondsToSelector:#selector(allHeaderFields)]) {
NSString* location = [[httpResponse allHeaderFields] valueForKey:#"Location"];
// do whatever with the redirect url
}
}
You coul also try urlEncoding your url including the data. Try what happens if you just call the following URL: http://quantuminfoways.com/crossfit_wodgenius/webservice/sync.php?udid=123&new=yes&uid=45&data=%20%7B%20createwod%20=%20%7B%20deletedcreatewod%20=%20(%20);%20newcreatewod%20=%20(%20);%20%7D;%20favorite%20=%20%7B%20deletedfavorite%20=%20(%20);%20newfavorite%20=%20(%20);%20%7D;%20gym%20=%20%7B%20deletedgym%20=%20(%20);%20newgym%20=%20(%20);%20%7D;%20workoutlog%20=%20%7B%20deletedworkoutlog%20=%20(%20);%20deletedworkoutlogtime%20=%20(%20);%20newworkoutlog%20=%20(%20);%20%7D;%20%7D