/babel-restify-api-v1

RESTful API for primarily handling interactions with Microsoft's Cognitive Services for Facial Recognition

Primary LanguageJavaScriptMIT LicenseMIT

Babel Restify API for Facial Auth Services

This repository contains a Node.js RESTful api service for facial recognition authentication. The service employs Microsoft's Cognitive Services for Facial Recognition and Detection.

This web service uses Babel to employ modern JavaScript syntax across the codebase.

Prerequisites

Download and install the following prerequisties in order to get started.

Quickstart

Follow the following set of simple instructions in order to get up and running quickly in a development environment.

  1. Globally install bunyan for logging
npm install -g bunyan
  1. Install dependencies
npm install
  1. Start MongoDB
brew services start mongodb
  • If you are on Windows you can quite simply follow the instructions here and run:
mongod
  1. Start the server in development mode
npm run watch

Facial Authentication

The service exposes two endpoints for Facial Authentication - registration and login.

Registration

  • /accounts/register

Login

  • /accounts/login

Both of these endpoints take a JSON Object body as part of the Request containing two fields:

  • Username: String
  • Image Data Url: String - Base64 Encoded Image Data Url - See Here!

Example

{
    username: 'YourAwesomeUsername',
    imageUrl: 'data:image/jpeg;base64,/9j/4AAQSkZ...FjWa0aP/Z'
}

Scores

The service is used in conjuction with a Front End mobile application developed using Ionic Native and targets android mobile devices. The API offers a number of routes for updating user scores for a simple mobile game based around mathematical arithmitic.

The routes service a HTTP PUT Request and are defined as follows:

Update Score Addition

  • /scores/addition

Update Score Subtraction

  • /scores/subtraction

Update Score Multiplication

  • /scores/multiplication

Each of the endpoints listed above take a JSON Object body as part of the Request containing two fields:

  • Username: String
  • Score: Number

Example

{
    username: 'YourAwesomeUsername',
    score: 100
}

Heroku Deployment

The web service has been deployed to Heroku using the Heroku CLI in conjunction with the MongoLab's mLab add-on for cloud hosted databases.

The service is currently available at: https://restify-face-service.herokuapp.com/

Deploy your own Heroku Service using these simple Heroku CLI commands where $MY_APP is your own application name.

heroku create $MY_APP

heroku addons:create mongolab

git add .
git commit -m 'Pushing to Heroku'
git push heroku master

Your brand new Node.js web service is availabe at - https://$MY_APP.herokuapp.com.

Verify that the Node.js web service is alive by using the healthcheck endpoint with a HTTP client such as cURL or Postman. A healthy application build and deployment should yield a HTTP 200 OK.

For Example:

curl -v https://$MY_APP.herokuapp.com/healthcheck

Video Demo

https://www.youtube.com/watch?v=9fjCsax9fjQ

NOTE: When you create a mLab add-on, the database connection URI is stored as a config var. Heroku config variables are equivalent to an environment variable, which you can use in development and your local environment. You can access this variable in your Node.js code as process.env.MONGODB_URI.

Microsoft Face API

An API Key for consuming the Microsoft Cognitive Services Face API can be obtained here!.

NOTE: This service currently employs a limited 30 day trial of the Face API service and is scheduled to expire on May 6th 2018.