touch node-cf-rest
$ cd node-cf-rest
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (cf-rest) node-cf-rest
version: (1.0.0)
description: Node.js consuming REST API on Cloud Foundry
entry point: (index.js)
test command:
git repository: (https://github.com/YoheiFukuhara/node-cf-rest.git)
keywords:
author:
license: (ISC)
About to write to /home/i348221/Apps/node/node-cf-rest/package.json:
{
"name": "node-cf-rest",
"version": "1.0.0",
"description": "Node.js consuming REST API on Cloud Foundry",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/YoheiFukuhara/node-cf-rest.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/YoheiFukuhara/node-cf-rest/issues"
},
"homepage": "https://github.com/YoheiFukuhara/node-cf-rest#readme"
}
Is this OK? (yes) yes
npm install --save express request
// Import modules
const express = require('express')
const request = require('request')
const app = express()
const port = process.env.PORT || 3000;;
// Get method
app.get('/', (req, res) => res.send('Hello World! for GET'))
app.get('/api', function (req, res) {
request.get({
uri: 'http://<host>:<port>/sap/opu/odata/sap/CB_CUSTOMER_SRV/Customers?$format=json',
headers: {'Content-type': 'application/json'},
auth: {
'user': '<user>',
'pass': '<password>',
'sendImmediately': false
}
}, function(err, req, data){
res.status(200).json(data)
console.log(data);
});
});
// Listen
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
{
"name": "node-cf-rest",
"version": "1.0.0",
"description": "Node.js consuming REST API on Cloud Foundry",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/YoheiFukuhara/node-cf-rest.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/YoheiFukuhara/node-cf-rest/issues"
},
"homepage": "https://github.com/YoheiFukuhara/node-cf-rest#readme",
"dependencies": {
"express": "^4.17.1",
"request": "^2.88.0"
}
}
$ node index.jp
Example app listening on port 3000!
---
applications:
- name: node-rest
random-route: true
memory: 128M
cf login
cf push node-rest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
25 | |
21 | |
12 | |
9 | |
9 | |
8 | |
8 | |
8 | |
7 |