1.1.0 • Published 7 years ago

r3connect v1.1.0

Weekly downloads
1
License
AGPL-3.0+
Repository
-
Last release
7 years ago

r3connect

JavaScript Style Guide

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.

Getting Started

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.

Prerequisites

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.

Installing

Node module

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);
});

Local Server

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
  }
}

Docker

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

Running the tests

Mocha tests are implemented and you can run all tests via

npm run test

Built With

  • hapi.js - Rich framework for building applications and services
  • node-rfc - nodejs RFC Connector
  • pool2 - Simple resource pool

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Julian Hundeloh - Initial work - jaulz

See also the list of contributors who participated in this project.

License

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 julian@hundeloh-consulting.ch.

Acknowledgments

1.1.0

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago