Skip to main content
Version: Next

Example

This example will walk you through the building of a fully functional servable app. The source code is available at https://github.com/servable-community/sample

We want to build a Servable service that:

  • #TODO

1. Install the generator​

npm install -g generator-servable

2. Generate a new server​

Generate a new servable app by running the command:

mkdir myapp
cd myapp
yo servable -q -t app -n "MyApp"

You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor.

You will be prompted to enter the basic informations needed to start a full-fledged servable app.

The command also installs all necessary dependencies you need to run servable.

3. Start your server​

Run the development server:

npm start

The cd command changes the directory you're working with. In order to work with your newly created servable-parse app, you'll need to navigate the terminal there.

The yarn start command builds your app locally and serves it through a development server, ready for you to view at http://localhost:1391/.

You can now open the Servable dashboard at http://localhost:4040 and view your application data.

info

Note that contrarily to Parse Server Dashboard, Servable Dashboard does not permit class creation and modification via the UI. This is to enforce the unique ability of Servable to predict schema and handle migrations automatically, thus avoiding environment discrepancies. The sole source of truth is the protocols designated schema files.

4. Add a class​

At this point the app is fully functional but lacks any high level behavior. By default a Servable service contains the following models: _User, _Session, _Installation, ServableApp Add a custom class:

yo servable -q -t class -n "BlogPost"
note

You can add class manually by adding a class payload to the app/schema/1.0.0/index.json

Restart the app to reflect the changes:

npm stop
npm start

5. Add protocols​

We want to make:

  • The app (thus servableApp class) able to send notifications and emails, have a reference for countries, locales and currency
yo servable -q -t communityprotocol --useAppProtocol --targetClassName ServableApp --protocol notifiable
  • The user (thus _User class) be followable, slugable, avatarable, localable, countryable
yo servable -q -t communityprotocol --useAppProtocol --targetClassName _User --protocol notifiable
  • A blog post (thus BlogPost class) to be commentable, reviewable, publishable, localable, countryable, slugable We want to Add a community protocol to the ServableApp to give it
yo servable -q -t communityprotocol --useAppProtocol --targetClassName BlogPost --protocol notifiable

At this point the app is useful for blogging.

Restart the app to reflect the changes:

npm stop
npm start

Uninstall

npm uninstall -g generator-servable