Technical Articles
Create API in NodeJS using SAP API Management
Here is a small demonstration on how to use SAP API Managment Service to design your API and deploy it in SAP Cloud Foundry.
Coding Lang – NodeJS
Cloud Platform – SAP Cloud Platform ( Neo Environment – API Development | CF Environment – API Deployment)
Source code editor: VS Code
CF CLI used – https://github.com/cloudfoundry/cli/wiki/V7-CLI-Installation-Guide
Below methods have been followed:
- API Structure is designed in SCP API Management service.
- Development of the API done locally in a windows desktop.
- Deployed the API in the SCP CF account.
Git Link – API Management
Step 1: Go to API Management service and click on Access API Designer.
The below URL will be opened.
API Designer screen
Step 2: Update this YAML file according to the requirement. In my scenario I have updated the file as – swagger yaml file
Step 3: Click on the highlighted option and give the details in the corresponding fields. Then update the project metadata.
Step 4: Get VS Code installed and open the folder in the workspace. Your project will look like below:
Open the project from VS Code
Step 5: Time to write some command scripts:
A. now Click on Terminal and execute the command “npm Install”:
after npm install is executed
B. Execute – “npm install random-number”
npm install random-number
C. Execute – “npm start”
npm start
“Dear reader, Please let me know on how to remove these vulnerabilities. ?”
Local server will run at: http://localhost:8080/docs
Next thing is my favourite. To see the docs in Swagger. It will appear as below:
localhost:8080
Note the below things if you are new to NodeJS-
Any Ways, lets move on.
Step 5: Update the file – Default.js from the git-url: Default.js
Note – according to your requirement change this section.
Then redeploy the API and test the API:
Step 6: Now lets deploy this.
Update manifest.yml from the url: https://github.com/sabarna17/SCP_API_Management/blob/master/manifest.yml
Install CF7 from the below url:
https://packages.cloudfoundry.org/stable?release=windows64&version=v7&source=github
- Once installed, goto cmd and use the below code to login to
cf7 login -a https://api.cf.eu10.hana.ondemand.com -u {loginid} -p {password} -o {orgName}
cf7 push -f manifest.yml
Cloud API is now deployed.
Login to the SCP CF to see the latest deployed API.
Your Space – Application – Overview
Your API is on cloud now. Enjoy testing it. I havn’t shown the steps related to use the API keys. It can be incorporated as per your requirement.
— Thanks for reading. Please do leave a comment if any changes are required.