Coder Social home page Coder Social logo

refarch-cloudnative-bff-inventory's Introduction

Node.js Express application as Business Facing Microservice

This project is part of the 'IBM Cloud Native Reference Architecture' suite, available at https://github.com/ibm-cloud-architecture/refarch-cloudnative

This project sits between the API gateway and the backend inventory microservices. It is built with Node.js Express and request framework with following functionality:

  • Route requests to backend Inventory microservice over Netflix Zuul.
  • Serve the application images
  • Augment the JSON data payload for Mobile and Web client

The Node.js application is managed under the inventory folder.

This application depends on Netflix Zuul service to be operational and routing to the backend Inventory microservice.

Routes to microservice URIs are defined in routes/itemservices.js. Run following command to set microservice base URL to Zuul proxy URL.

# cd inventory
# /bin/bash set-zuul-proxy-url.sh [-m <microservice-app-name> -c <context-path>] -z <zuul-cluster-url>
   
  defaults: -m inventory-microservice -c micro

Run the application locally:

  • Run the application:

    # npm install
    # npm start
    

This will start the application on port 3001.

  • Validate the local application

http://localhost:3001/api/items/validate

To test the actual endpoint with backend services http://localhost:3001/api/items

Available APIs

  • List all items in inventory. Send GET request to /api/items
  • List item by id. Send GET request to /api/items/{id}
  • List all items containing name. Send GET request to /api/items//name/{name}
  • List all items with price less than or equal to. Send GET request to /api/items/price/{price}
  • Add item. Send json paylond with POST request to /api/items
  • Update item by id. Send json payload with PUT request to /api/items/update/{id}
  • Delete item by id. Send DELETE request to /api/items/delete/{id}

Deploy to Bluemix Cloud Foundry runtime:

  1. Create Auto-Scaling service. manifest.yml has Auto-Scaling service name set to cloudnative-autoscale. If you have an existing Auto-Scaling service with a different name, then edit manifest.yml to update the service name.

    To create a new Auto-Scaling service with name used in manifest.yml, use the following command.

    # cf create-service Auto-Scaling free cloudnative-autoscale
    
  2. Set Cloud Foundry application name. manifest.yml has the application and host names set to inventory-bff-app. You can leave the name as-is or change it. Now, deploy the application.

    # cf push
    
  3. Validate the Cloud Foundry application. http://inventory-bff-app.mybluemix.net/api/items/validate

This completes deployment of the application to Bluemix Cloud Foundry runtime.

refarch-cloudnative-bff-inventory's People

Contributors

gangchen03 avatar ssibm avatar osowski avatar jkwong888 avatar

Watchers

James Cloos avatar Fabio Gomez Diaz avatar  avatar  avatar Budi Darmawan avatar  avatar  avatar

refarch-cloudnative-bff-inventory's Issues

Application crashes when item ID is not found in database

When the item ID is not found, the microservice return a null string. However the bff always parse the return value as a JSON string, hence when the return value is null it crashes. Suggestion is to check whether the result is null and then either return an error or insert an empty JSON object {} in /inventory/routes/itemservices.js

                        if (0 === body.length) {
                             body = "{}";
                        }
                        var bodyJson = JSON.parse(body);

or

                        if (0 === body.length) {
                             return res.send({"error":"item not found"});
                        }
                        var bodyJson = JSON.parse(body);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.