# 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 ## PART I: Download & Build on local ### 1) Clone the repository, install node packages and verify routes locally ``` //on local git clone https://github.com/zowe/sample-cli-api cd sample-cli-api npm install npm run dev ``` Open your local browser and try accessing `http://localhost:18000/accounts/` `http://localhost:18000/accounts/1` `http://localhost:18000/accounts/1/cars/` ### 2) Transfer project files from local to remote host ``` cd sample-cli-api npm run dist scp -r dist ibmuser@my.mainframe.com:/sample-cli-api ``` ## PART II: Deploy with Zowe on server ### 1) login ``` ssh ibmuser@my.mainframe.com ``` ### 2) install dependencies ``` cd /sample-cli-api npm install --only=prod ``` ### 3) Manage lifecycle of service with core zowe components Use property `EXTERNAL_COMPONENT` located in file `$INSTANCE_DIR/instance.env` Append it with your service lifecycle scripts. In our sample it is: ``` vi INSTANCE_DIR/instance.env EXTERNAL_COMPONENTS=/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-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-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. In effect, service can be accessed with following url: `https://{host}:{GATEWAY_PORT}/{gatewayUrl}/{serviceId}/*` where `GATEWAY_PORT` is configured in $INSTANCE_DIR/instance.env Verify by accessing following: `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 **API Catalog** ![APICatalog_Dashboard](./screenshots/APICatalog_Dashboard.png) ![ApiCatalog_SampleNodeApi_SwaggerDoc](./screenshots/ApiCatalog_SampleNodeApi_SwaggerDoc.png) **Discovery Service Dashboard** ![DiscoveryService_Dashboard](./screenshots/DiscoveryService_Dashboard.png)