alsoicode / expression-consumer

Consumes randomly generated expressions of addition between two positive integers and returns a response

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expression Consumer

A ReSTful Node.js service written in Restify that consumes an addition expression, evaluates it and reports the solution back to the producer.

Requirements

Installation

  • Clone this repository, or download the source as a .zip archive
  • cd into the cloned directory or unzipped archive
  • install dependencies via npm: $ npm install
  • Create a .env file in the project root to set up your local Node environment variable with the following contents: NODE_ENV=local

Configuration

The only option you may need to configure is the Restify server port, located in settings/local.json. By default this port is set to 4000.

Logging

To enable logging: $ mkdir logs && touch logs/run.log

Running the server

  • via nodemon: $ nodemon app.js
  • via node: $ node app.js

With the default settings, the server will be running at: localhost:4000

Endpoints

GET: /heartbeat

Simple healthcheck for the service.


GET: /consume

Endpoint for consuming an addition expression and reporting the solution back to the producer.

Required Parameters
  • None
Returns
  • Status Code: 200
  • Response: {"solution-recorded": true, "expression": "25+65=", "solution": 90}
  • Content-Type: JSON

Usage

Step 1:

Download, configure and start the Expression-Producer service.

Step 2:

Start the Expression-Consumer service.

See Results!

Open a browser, hit the /consume endpoint and marvel at the wonders of the addition of random positive integers!

Alternatively, you can also use Postman to view the JSON result returned.

Tests

Tests are written BDD-style with Mocha and Supertest and can be run using Grunt: $ grunt test

Benchmarking

Benchmarking is available as a Grunt task: $ grunt benchmark. Results are generated in HTML format and may be found in the /generated/output.html file, viewable in a web browser.

To run the benchmarks, you must first run the server in test mode:

$ NODE_ENV=test node app.js

then, in a separate terminal tab or window, run the benchmark task:

$ cd to application
$ grunt benchmark

Diagrams

UML diagrams for activity and sequence are located in the ./diagrams directory:

  • expression-consumer-activity.html
  • expression-consumer-sequence.html

and are viewable via your web browser.

About

Consumes randomly generated expressions of addition between two positive integers and returns a response


Languages

Language:JavaScript 65.6%Language:HTML 34.4%