Created
July 23, 2010 15:12
-
-
Save c4milo/487557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CREATIONAL API | |
//create resources | |
//When CREATIONAL API is included, automatically it adds the property resourceTemplate | |
// To the USER API. it's like a mixin | |
var template = server.component('Twitter').template(); | |
template.suggested_name = 'MyTwitter' | |
template.desc = 'My personal Twitter account' | |
template.params.name = 'MyTwitterAccountName' | |
template.params.password = '******' | |
server.createResource(template, function(data){ | |
/*data.uri | |
data.name | |
data.status*/ | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DISCOVERY API | |
server = restxjs.connect('http://locahost:8080') | |
//list components | |
var components = server.components() | |
components.Twitter.uri | |
components.Twitter.desc | |
components.Google.uri | |
components.Google.desc | |
//get information about an specific component | |
var twitter = server.component('Twitter'); | |
twitter.uri | |
twitter.name | |
twitter.desc | |
twitter.services | |
twitter.params | |
... (the same json structure defined in the Server API | |
//list resources | |
var resources = server.resources(); | |
resources.MyTwitter.uri | |
resources.MyTwitter.name | |
resources.MyTwitter.desc | |
resources.MyTwitter.services.status.uri | |
resources.MyTwitter.services.status.desc | |
resources.MyTwitter.services.timeline.uri | |
resources.MyTwitter.services.timeline.desc | |
resources.MyGoogle.uri | |
resources.MyGoogle.name | |
resources.MyGoogle.desc | |
resources.MyGoogle.services.search.uri | |
resources.MyGoogle.services.search.desc | |
//list services of a specific resource | |
//When the discovery api is included, automatically it adds the function services() | |
// to the USER API. It's like a mixin | |
var services = server.resource('MyTwitter').services(); | |
services.status.uri | |
services.status.desc | |
services.timeline.uri | |
services.timeline.desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USER API | |
server = restxjs.connect('http://localhost:8080') | |
var twitter = server.resource('MyTwitter'); | |
twitter.status('Updating my status with restxjs', function(data) { | |
//it can fires an event 'data' as well | |
}); | |
var google = server.resource('MyGoogle'); | |
google.search('restx', function(data) { | |
//do something | |
}); | |
var input = { name: 'Foo', | |
address: '123 xxxzzz, Pl. CA' | |
} | |
var customer = server.resource('Customer'); | |
customer.create(input, function(data) { | |
//do something | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment