(updated: 20170318)
This is part 2 in a series to build QAVideos. QAVideos is a Question and Answer application that uses videos instead of text. Think of QAVideos as StackOverflow meets Youtube. QAVideos will use LoopBack, API Connect, Open API Initiative (OAI formerly Swagger.io), OpenWhisk, Object Storage.
In part 1 ‘QAVideos (Part 1), Adding User Management to Node.js with API Connect‘, I showed how to add User Management to a Node.js app using API Connect.
In this part 2, I will add a custom data model, i.e. a Video model and use ORM to persist data to a PostGreSQL database.
Part 3 (to be updated) is found here, which adds model extensions and uses Open API Initiative (formerly Swagger) support.
Source code for QAVideos is released per part via https://github.com/remkohdev/qavideos/releases.
Requirements
- Install Node.js and npm,
- Install API Connect.
- Check if the ‘apic’ tool is installed, by running ‘apic -v’ from the commandline. If not installed, follow the installation instructions, here.
- Get the source code for part 1 of this tutorial and follow the installation instructions for QAVideos Release v1.0.0. First clone the repository, then make sure you fetch all the remote tags to your local repository, and then checkout the v1.0.0 tag.
git clone https://github.com/remkohdev/qavideos.git
git fetch --all --tags --prune
git checkout tags/v1.0.0
Table of Contents
- Create Data Model
- Define Relation
- Adding ACL
- Add Video Functionality
- Add Data Source
1. Create Data Model
First, test if QAVideos (part 1) is running correctly. Open a commandline, change your directory to the root directory of your QAVideos application, type ‘apic start’, and browse to ‘http://0.0.0.0:4001‘ in your browser.
Now, I want to add a custom model ‘Video’ so that users can manage their list of videos. To do this, I create a model for the Video with the ‘apic’ tool, and define the relationship between Video and User (a User can own many videos), and specify the access level of Users to Video objects using an Access Control List (ACL).
Continue reading