Skip to content

_Prtcl dev guide 4: Configuring service providers

guillem.cordoba edited this page Nov 12, 2019 · 1 revision

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.

Developer guide

1 - Installing the tools

2 - Looking around

3 - Cortex modules

4 - Configuring service providers

5 - Configuring modules

6 - Loading modules with micro-orchestrator

7 - Displaying an entity

8 - Adding the Evees module

9 - Adding multiple backends

[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

Clone this wiki locally