r3connect is a lean wrapper of node-rfc that provides comfortable access to SAP back-ends via a simple REST API or via a Promise-based API. All remote function calls are handled via connection pools in order to reuse connections as much as possible and run function calls in parallel. Technical errors are prettified and mapped to corresponding HTTP responses. In favor of simplification this module is also designed to run in a container with Docker.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Install the latest LTS version of Node.js.
In case you did not use the installer, make sure that node
and npm
are available in the terminal.
In order to use r3connect you need to obtain the SAP NW RFC Library from the SAP Service Marketplace Software Download Center.
If you want to build a Docker container, also install Docker.
In case you would like to call a RFC within your existing node script without using the REST API you can also install r3connect as a dependency:
npm install r3connect --save
Please make sure that you installed node-rfc
npm install node-rfc --save
Afterwards you can require r3connect and call any RFC:
const r3connect = require('r3connect');
// Define connection configuration
const configuration = {
applicationServer: 'example.company.corp',
instanceNumber: 1,
username: 'testuser',
password: 'helloworld',
client: 123,
router: '',
};
// Acquire client from pool
r3connect.Pool.get(configuration).acquire()
.then(function (client) {
// Actually call the back-end
return client.invoke('RSIM_RFC_CONNECTION_TEST', {
iv_test: 'test'
});
})
.then(function (response) {
// Output response
const result = response[0];
const meta = response[1];
console.log('Result:');
console.log(result);
console.log('Metadata:');
console.log(meta);
})
.catch(function (error) {
// Output error
console.log('Error:');
console.log(error);
});
Or alternatively in ES6 syntax:
import { Pool } from 'r3connect';
// Define connection configuration
const configuration = {
applicationServer: 'example.company.corp',
instanceNumber: 1,
username: 'testuser',
password: 'helloworld',
client: 123,
router: '',
};
// Acquire client from pool
Pool.get(configuration).acquire()
.then((client) => {
return client.invoke('RSIM_RFC_CONNECTION_TEST', {
iv_test: 'test'
});
})
.then(([result, meta]) => {
console.log('Result:');
console.log(result);
console.log('Metadata:');
console.log(meta);
})
.catch((error) => {
console.log('Error:');
console.log(error);
});
Open the terminal and install r3connect globally. This usually takes some time which you can use to grab a cup of coffee or tea.
npm install r3connect -g
To generate a new project, navigate to the directory where you want it to be and type. Skip the parts that you cannot or do not want to answer.
npm init
This will generate a package.json
which will define your new project including all dependencies.
Afterwards kick-start your first r3connect project by running:
r3connect init
This should initialize your project folder with all necessary files to start with. If you want to start a local server run:
r3connect server
Depending on which hostname and port you defined in config.js
the server will be available via https://localhost:3001/ by default.
For example, if you want to invoke the remote-enabled function module RSIM_RFC_CONNECTION_TEST
, execute the following POST request.
The endpoint in this case would be https://localhost:3001/rfc/RSIM_RFC_CONNECTION_TEST and the body of the request would contain values for applicationServer
, instanceNumber
, client
, username
, password
and parameters
(JSON object).
POST /rfc/RSIM_RFC_CONNECTION_TEST HTTP/1.1
Host: localhost:3001
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="applicationServer"
example.company.corp
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="username"
testuser
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="password"
helloworld
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="instanceNumber"
1
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="client"
123
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="parameters"
{ "iv_test": "test" }
------WebKitFormBoundary7MA4YWxkTrZu0gW--
An example response would look like this:
{
"result": {
"E_INVOKED": "X"
},
"meta": {
"invokeTime": 54,
"connectTime": 102
}
}
Similar to the local server, open the terminal and install r3connect globally:
npm install r3connect -g
To generate a new project, navigate to the directory where you want it to be and type. Skip the parts that you cannot or do not want to answer.
npm init
This will generate a package.json
which will define your new project including all dependencies.
Afterwards kick-start your first r3connect project by running:
r3connect init
This should initialize your project folder with all necessary files to start with. If you want to create the Docker container, run:
r3connect docker
Mocha tests are implemented and you can run all tests via
npm run test
- hapi.js - Rich framework for building applications and services
- node-rfc - nodejs RFC Connector
- pool2 - Simple resource pool
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Julian Hundeloh - Initial work - jaulz
See also the list of contributors who participated in this project.
This project is licensed under the AGPL-3.0+ License - see the LICENSE.md file for details. If you are interested in other options please get in touch via [email protected].