sample cli version of sample node api

Signed-off-by: Nakul Manchanda <nakul.manchanda@ibm.com>
This commit is contained in:
Nakul Manchanda
2020-08-28 01:06:18 -05:00
parent 376db7a2fb
commit 78c372660b
9 changed files with 48 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
# sample-node-api
# sample-cli-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.
## Steps
@@ -9,8 +9,8 @@ A sample node js api for finding cars and accounts for a dealership,its used her
```
//on local
git clone https://github.com/zowe/sample-node-api
cd sample-node-api
git clone https://github.com/zowe/sample-cli-api
cd sample-cli-api
npm install
npm run dev
```
@@ -25,9 +25,9 @@ Open your local browser and try accessing
```
cd sample-node-api
cd sample-cli-api
npm run dist
scp -r dist ibmuser@my.mainframe.com:</usr/lpp/extender>/sample-node-api
scp -r dist ibmuser@my.mainframe.com:</usr/lpp/extender>/sample-cli-api
```
## PART II: Deploy with Zowe on server
@@ -39,7 +39,7 @@ ssh ibmuser@my.mainframe.com
### 2) install dependencies
```
cd </usr/lpp/extender>/sample-node-api
cd </usr/lpp/extender>/sample-cli-api
npm install --only=prod
```
@@ -52,20 +52,20 @@ Append it with your service lifecycle scripts.
In our sample it is:
```
vi INSTANCE_DIR/instance.env
EXTERNAL_COMPONENTS=</usr/lpp/extender>/sample-node-api/bin
EXTERNAL_COMPONENTS=</usr/lpp/extender>/sample-cli-api/bin
```
We expect following in service folder `start.sh`, `configure.sh` and `validate.sh`.
In our case its bin folder with relevant scripts.
`configure.sh` it adds static definition for sample-node-api to folder ${INSTANCE_DIR}/workspace/api-mediation/api-defs in IBM-850 encoding
`configure.sh` it adds static definition for sample-cli-api to folder ${INSTANCE_DIR}/workspace/api-mediation/api-defs in IBM-850 encoding
`start.sh` starts node app on configured port
`env.sh` its custom script use to configure port for our node app, feel free to use your desired way
### 4) Access newly deployed webservice
Please see static definition file `sample-node-api.yml`
It configures service endpoint as `sample-node-api` with property `serviceId`
Please see static definition file `sample-cli-api.yml`
It configures service endpoint as `sample-cli-api` with property `serviceId`
We also provide api gateway base path `api\v1` with property `gatewayUrl` in same file.
@@ -75,9 +75,9 @@ In effect, service can be accessed with following url:
where `GATEWAY_PORT` is configured in $INSTANCE_DIR/instance.env
Verify by accessing following:
`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/`
`https://my.mainframe.com:7554/api/v1/sample-cli-api/accounts/`
`https://my.mainframe.com:7554/api/v1/sample-cli-api/accounts/1/`
`https://my.mainframe.com:7554/api/v1/sample-cli-api/accounts/1/cars/`
### 5) Registered With API Catalog

2
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{
"name": "sample-node-api",
"name": "sample-cli-api",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,

View File

@@ -1,5 +1,5 @@
{
"name": "sample-node-api",
"name": "sample-cli-api",
"version": "1.0.0",
"description": "",
"main": "index.js",

23
sample-cli-api.yml Normal file
View File

@@ -0,0 +1,23 @@
#
services:
- serviceId: sample-cli-api
title: sample-cli-api
description: Sample CLI API
catalogUiTileId: sample-cli-api
instanceBaseUrls:
- http://localhost:17000/
homePageRelativeUrl: # Home page is at the same URL
routedServices:
- gatewayUrl: api/v1 # [api/ui/ws]/v{majorVersion}
serviceRelativeUrl:
apiInfo:
- apiId: com.ibm.sample-cli-api
gatewayUrl: api/v1
version: 1.0.0
swaggerUrl: http://localhost:17000/api-docs
documentationUrl: http://localhost:17000/api-docs-ui
catalogUiTiles:
sample-cli-api:
title: sample-cli-api
description: Sample CLI API

View File

@@ -1,24 +0,0 @@
#
services:
- serviceId: sample-node-api
title: Sample-Node-API
description: Sample Node API
catalogUiTileId: sample-node-api
instanceBaseUrls:
- http://localhost:18000/
- http://localhost:19000/
homePageRelativeUrl: # Home page is at the same URL
routedServices:
- gatewayUrl: api/v1 # [api/ui/ws]/v{majorVersion}
serviceRelativeUrl:
apiInfo:
- apiId: com.ibm.sample-node-api
gatewayUrl: api/v1
version: 1.0.0
swaggerUrl: http://localhost:18000/api-docs
documentationUrl: http://localhost:18000/api-docs-ui
catalogUiTiles:
sample-node-api:
title: Sample-Node-API
description: Sample Node API

View File

@@ -65,7 +65,7 @@ function setUpParams() {
.option('s', {
alias: 'service',
description: 'service-for path',
default: 'sample-node-api'
default: 'sample-cli-api'
})
.option('p', {
alias: 'port',

View File

@@ -19,7 +19,7 @@ router.use('/cars', cars);
router.use('/accounts', accounts);
router.use('/', swagger);
router.get('/', (req, res) => res.send('Sample Node API'));
router.get('/', (req, res) => res.send('Sample CLI API'));
router.get('/health', (req, res) => {
const healthcheck = {
uptime: process.uptime(),

View File

@@ -1,8 +1,8 @@
{
"swagger":"2.0"
,"info":{"description":"Sample Node API"
,"info":{"description":"Sample CLI API"
,"version":"1.0"
,"title":"Sample Node API"}
,"title":"Sample CLI API"}
,"host":"localhost:18000"
,"basePath":"/"
,"tags":[{"name":"Accounts","description":"Accounts API"},{"name":"Cars","description":"Cars API"}]

View File

@@ -1,16 +1,16 @@
## start locally
node server/app.js --service sample-node-api --port 18000 --key sslcert/server.key --cert sslcert/server.cert -v
node server/app.js --service sample-cli-api --port 18000 --key sslcert/server.key --cert sslcert/server.cert -v
cd ~/zowe/extenders/sample-node-api
cd ~/zowe/extenders/sample-cli-api
## start on z/os uss
KEYSTORE_DIRECTORY=~/zowe/keystore
KEYSTORE_ALIAS=localhost
KEYSTORE_PREFIX="${KEYSTORE_DIRECTORY}/${KEYSTORE_ALIAS}/${KEYSTORE_ALIAS}.keystore"
KEYSTORE_KEY=${KEYSTORE_PREFIX}.key
KEYSTORE_CERTIFICATE=${KEYSTORE_PREFIX}.cer-ebcdic
node server/app.js --service sample-node-api --port 18000 --key ${KEYSTORE_KEY} --cert ${KEYSTORE_CERTIFICATE} -v
node server/app.js --service sample-cli-api --port 18000 --key ${KEYSTORE_KEY} --cert ${KEYSTORE_CERTIFICATE} -v
# register with API ML layer
cd ~/zowe/extenders/sample-node-api
iconv -f IBM-1047 -t IBM-850 sample-node-api.http.yml > bin/sample-node-api-http.yml
iconv -f IBM-1047 -t IBM-850 sample-node-api.http.yml > ~/zowe/instance/workspace/api-mediation/api-defs/sample-node-api.yml
cd ~/zowe/extenders/sample-cli-api
iconv -f IBM-1047 -t IBM-850 sample-cli-api.http.yml > bin/sample-cli-api-http.yml
iconv -f IBM-1047 -t IBM-850 sample-cli-api.http.yml > ~/zowe/instance/workspace/api-mediation/api-defs/sample-cli-api.yml