-
Notifications
You must be signed in to change notification settings - Fork 13
_Prtcl dev guide 4: Configuring service providers
A service provider is a connection to any back-end (centralized or decentralized) that provides certain funcionalities to use in our modules.
Each Cortex module offers an interface that the service providers for this module should implement. Let's look at DocumentsProvider:
export interface DocumentsProvider extends Source {
createTextNode(node: TextNode): Promise<string>;
}
Note: most of service providers implement the Source interface. This standarization is necessary in order to support links to any kind of content-addressable object.
Any service that implements this interface will be able to interact with all the components inside documentsModule.
Now, let's import the DocumentsIpfs provider and configure it:
import { IpfsConnection } from '@uprtcl/connections';
import { DocumentsIpfs } from '@uprtcl/documents';
const ipfsConnection = new IpfsConnection({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https'
});
const documentsProvider = new DocumentsIpfs(ipfsConnection);
That's it! We now have a service that connects to Ipfs and is able to get and create documents. You can call its functions to create and get TextNodes:
import { TextType } from '@uprtcl/documents';
// Wait until the provider is ready
await documentsProvider.ready();
const createdDocumentId = await documentsProvider.createTextNode({
text: '',
type: TextType.Paragraph,
links: []
});
const fetchedDocument = await documentsProvider.get(createdDocumentId);
console.log(fetchedDocument);
When you are done, you can proceed to 5 - Configuring modules.
_Prtcl resources: Overview, Spec, Dev guide, API reference
4 - Configuring service providers
6 - Loading modules with micro-orchestrator
[TBD]10 - adding lens selection
[TBD] Using Cortex without modules
[TBD] Building a pattern
[TBD] Building a lens
[TBD] Building a service provider
[TBD] Building a Cortex module
[TBD] Customizing the lenses module
[TBD] Building a plugin for the lenses module