Giter VIP home page Giter VIP logo

sample-node-api's Introduction

sample-node-api

A sample node js api for finding cars and accounts for a dealership,its used here to demonstrate the steps to extend API/ML with your own rest api.

Manual Installation

Steps

Note
Only rest api with https support can be deployed behind API/ML, make sure to enable https support in your rest api.

Note
Replace /u/zowe/ibmuser/1.0.0/ with your zowe installation folder
Replace [email protected] with your username and mainframe-ip

This sample express app, has https enabled already.

Download and transfer project files

1) Clone the repository, install node packages and verify routes locally

//on local
git clone https://github.com/zowe/sample-node-api
cd sample-node-api
npm install
npm start

Open your local browser and try accessing
https://localhost:4000/accounts/
https://localhost:4000/accounts/1
https://localhost:4000/accounts/1/cars/

2) Transfer project files from local to remote host

Note
Don't transfer node_modules folder, we can do install npm install later on remote server itself to pull down required node packages

// on remote - Create placeholder directory for your node app
ssh [email protected]
cd /u/zowe/ibmuser/1.0.0/
mkdir sample-node-api

//on local - use scp to transfer project files
scp data.js [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api
scp package.json [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api
scp package-lock.json [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api
scp sample-node-api.yml [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api/sample-node-api.yml.1047

scp -r scripts [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api/scripts
scp -r server [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api/server
scp -r sslcert [email protected]:/u/zowe/ibmuser/1.0.0/sample-node-api/sslcert

Setup and Register API on host

1) Install node packages required by project

// on remote
cd /u/zowe/ibmuser/1.0.0/sample-node-api
npm install

2) Modify startup script permission

Change unix permission of start up shell script start-sample-node-api.sh, so run-zowe.sh script can start a API

// on remote
cd /u/zowe/ibmuser/1.0.0/sample-node-api/scripts
chmod 755 start-sample-node-api.sh
chmod 755 restart-sample-node-api.sh

3) Register a plugin API/ML layer using yml file

Note
Require encoding for sample-node-api.yml is IBM-850, use iconv utility to convert it to correct format

Yaml config file needs to be present in api-defs folder along-with other statically discovered API example jobs.yml, uss.yml etc

// on remote
cd /u/zowe/ibmuser/1.0.0/sample-node-api
iconv -t IBM-850 -f IBM-1047 sample-node-api.yml.1047 > sample-node-api.yml
mv sample-node-api.yml ../api-mediation/api-defs/

4) Modify zowe startup script to include API startup script

Edit run-zowe.sh on remote append node app startup script

// on remote
cd /u/zowe/ibmuser/1.0.0/scripts/internal/
vi run-zowe.sh

Append following start command for sample-node-api, among similar command from another services

`dirname $0`/../../sample-node-api/scripts/start-sample-node-api.sh

Run Project

1) Restart Zowe

Note
Replace ZOWESVR below with name of your installed zowe instance

from TN3270 terminal

# stop/cancel
/c ZOWESVR

# start/restart
/s ZOWESVR

Or, we can use zowe helper scripts to restart zowe

ssh [email protected]
cd /u/zowe/ibmuser/1.0.0/scripts
./zowe-stop.sh
./zowe-start.sh

2) Access newly deployed webservice behind api/v1

https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/
https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/1/
https://my.mainframe.com:7554/api/v1/sample-node-api/accounts/1/cars/

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.