By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

js -> REST API mapping

P: n/a
I'm looking for advice. I have been playing with Konfabulator which
embeds SpiderMonkey (apparently using the JavaScript 1.5 api) for
scripting "widgets" - various bits of eye candy that sit on your
desktop.

One widget I would like to build is a display of a person's flickr
photostream. Flickr has a nice API, available via REST, XML/RPC, and
SOAP. I'd like to map the flickr API to javascript, having it do url
fetches and parsing the resultant XML results "behind the scenes", but
I don't want to manually create every function, especially since there
would be a huge amount of redundancy in doing so. The scheme
programmer in me immediately reaches for macros, but it does not appear
that JavaScript has macros. It does appear to have first-order
functions, so my gears are still turning.

So my idea is to build an array of function names (as strings), args
(as an array of objects), and xpath expressions (as strings) and
somehow dynamically generate the necessary functions at load time. I'm
a bit stumped on how to get these functions to be available at the top
scoping level. I'm going to sit down with the ECMAScript ed. 3 spec
tonight, but, again, am interested in general advice.

Does anyone have any suggestions on a) how to do this or even better b)
other, better ideas on making this REST api available seamlessly via
JavaScript?

Jul 27 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
jk******@gmail.com wrote:
I'm looking for advice. I have been playing with Konfabulator which
embeds SpiderMonkey (apparently using the JavaScript 1.5 api) for
scripting "widgets" - various bits of eye candy that sit on your
desktop.

One widget I would like to build is a display of a person's flickr
photostream. Flickr has a nice API, available via REST, XML/RPC, and
SOAP. I'd like to map the flickr API to javascript, having it do url
fetches and parsing the resultant XML results "behind the scenes", but
I don't want to manually create every function, especially since there
would be a huge amount of redundancy in doing so. The scheme
programmer in me immediately reaches for macros, but it does not appear
that JavaScript has macros. It does appear to have first-order
functions, so my gears are still turning.
I understand little of what you're saying, but I gather that you need
to either use a small number of functions to perform lots of tricks but
have a large number of names, or logically create a large number of
functions to each do a single, slightly different trick?

well...

Synopsis:
x = function ( arg1, arg2 ) {
// a function that does a large number of things, depending on args
}

y = x; // What's in a name?
z = x; // Just a reference, really.

x = 'code' +
'more code' +
'even more code!';

y = new Function( 'arg1', 'arg2', x );
z = new Function( 'arg1', x + 'still more code' );
So my idea is to build an array of function names (as strings), args
(as an array of objects), and xpath expressions (as strings) and
Don't know what an xpath is, but hey-- why use an array of function
names (as strings) when you can use an array of functions (as
references)?

x = [
function ( args ) { /* things that we do */ },
function ( args ) { /* other things that need doing */ },
function ( args ) { /* so much to do... */ }
];

x[0]( args ); // things that we do
x[1]( args ); // other things that need doing
somehow dynamically generate the necessary functions at load time. I'm
a bit stumped on how to get these functions to be available at the top
scoping level. I'm going to sit down with the ECMAScript ed. 3 spec
tonight, but, again, am interested in general advice.
See Synopsis above.
Does anyone have any suggestions on a) how to do this or even better b)
other, better ideas on making this REST api available seamlessly via
JavaScript?


Don't know the API, but hopefully the Synopsis helps.

It occurs to me that you might be trying to call functions in the API
by using same-named functions in JS.

REST = {
call: function ( fname, fargs ) {
// do the call for fname using fargs
// however it is that REST actually does these things
// Use other properties of your new REST object as needed
}
}

REST.call( 'get', [ thing1, thing2 ] );


Hopefully that helped you in some way.

Jul 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.