-
Notifications
You must be signed in to change notification settings - Fork 53
Tutorial: Custom Provider
So you're sold on freedom.js, but want to use it with snazzynewsocialsite.com? Or maybe you just prefer your own implementation of one of the existing APIs? Maybe you even want to make a new API so freedom.js can interoperate with some new and different thing.
In any case, you're in luck - freedom.js supports both the creation of custom providers to existing APIs, and new APIs with their own providers. All of this is done by creating modules, and specifying what they provide or depend on in their manifest.
If you want to make a custom provider for some API "apiname", it's just a matter of adding the following to your manifest:
"provides": ["apiname"]
If this is some new API you will also need to specify it:
"api": { "apiname": { ... } }
For details about specifying your own API look at how the core ones are structured in interface/.
In your actual JavaScript implementation you register the provider with:
freedom.apiname().providePromises(myClass);
For someone else to depend on/use it, they would need to set the dependency in their manifest:
dependencies: { "myapi": { "url": "other.manifest", "api": "apiname" } }
And finally instantiate it in their actual application:
var instance = freedom.myapi();