|
| 1 | +.. _Connection: |
| 2 | + |
| 3 | +Creating a Connection |
| 4 | +===================== |
| 5 | + |
| 6 | +Transports |
| 7 | +---------- |
| 8 | + |
| 9 | +The ``Connection`` Class uses ``ODBC``, ``SSH``, ``idb``, and ``REST`` transports to access ``XMLSERVICE``. |
| 10 | +Some transports require prerequisite setup. Learn morre about each transport below. |
| 11 | + |
| 12 | +ODBC |
| 13 | +^^^^ |
| 14 | +.. _guide: https://github.com/IBM/ibmi-oss-examples/blob/master/odbc/odbc.md#table-of-contents |
| 15 | + |
| 16 | +The ODBC transport establishes a database connection and calls XMLSERVICE stored procedure. |
| 17 | +Refer to the odbc guide_ for setup instructions. |
| 18 | + |
| 19 | +SSH |
| 20 | +^^^ |
| 21 | +The SSH transport executes ``xmlservice-cli`` program via ssh. |
| 22 | +Install ``xmlservice-cli`` before using the ``SSH`` transport. |
| 23 | + |
| 24 | +.. code-block:: bash |
| 25 | +
|
| 26 | + $ yum install itoolkit-utils |
| 27 | +
|
| 28 | +idb |
| 29 | +^^^^ |
| 30 | + |
| 31 | +The idb transport establishes a database connection and calls the XMLSERVICE stored procedure. |
| 32 | + |
| 33 | +**NOTE** the idb transport is only supported on an IBM i system. |
| 34 | + |
| 35 | +REST |
| 36 | +^^^^ |
| 37 | +The REST transport makes an HTTP request to an endpoint that process the XML input and returns XML output. |
| 38 | + |
| 39 | +Initial configuration is required for the endpoint. |
| 40 | + |
| 41 | +A quick example is to add the following to ``/www/apachedft/conf/httpd.conf``. |
| 42 | + |
| 43 | + |
| 44 | +.. code-block:: apache |
| 45 | +
|
| 46 | + ScriptAlias /cgi-bin/ /QSYS.LIB/XMLSERVICE.LIB/ |
| 47 | + <Directory /QSYS.LIB/XMLSERVICE.LIB/> |
| 48 | + AllowOverride None |
| 49 | + Require all granted |
| 50 | + SetHandler cgi-script |
| 51 | + Options +ExecCGI |
| 52 | + </Directory> |
| 53 | +
|
| 54 | +Connection API |
| 55 | +-------------- |
| 56 | + |
| 57 | +.. autoclass:: Connection |
| 58 | + :members: |
| 59 | + |
| 60 | +.. autofunction:: connectionConfig |
| 61 | +.. autofunction:: odbcOptions |
| 62 | +.. autofunction:: sshOptions |
| 63 | +.. autofunction:: idbOptions |
| 64 | +.. autofunction:: restOptions |
| 65 | +.. autofunction:: runCallback |
| 66 | + |
| 67 | +Examples |
| 68 | +-------- |
| 69 | + |
| 70 | +Creating a ``Connection`` using the ``ODBC`` tranport. |
| 71 | + |
| 72 | +.. code-block:: js |
| 73 | +
|
| 74 | + const connection = new Connection({ |
| 75 | + transport: 'odbc', |
| 76 | + transportOptions: { host: 'myhost', username: 'myuser', password: 'mypassword'} |
| 77 | + }); |
| 78 | +
|
| 79 | +Creating a ``Connection`` using the ``ODBC`` tranport with a ``DSN``. |
| 80 | + |
| 81 | +.. code-block:: js |
| 82 | +
|
| 83 | + const connection = new Connection({ |
| 84 | + transport: 'odbc', |
| 85 | + transportOptions: { dsn: '*LOCAL'} |
| 86 | + }); |
| 87 | +
|
| 88 | +Creating a ``Connection`` with ``ssh`` tranport using private key to authenticate. |
| 89 | + |
| 90 | +.. code-block:: js |
| 91 | +
|
| 92 | + const connection = new Connection({ |
| 93 | + transport: 'ssh', |
| 94 | + transportOptions: { host: 'myhost', username: 'myuser', password: 'mypassword' } |
| 95 | + }); |
| 96 | +
|
| 97 | +Creating a ``Connection`` using the ``ssh`` tranport with a private key to authenticate. |
| 98 | + |
| 99 | +.. code-block:: js |
| 100 | +
|
| 101 | + const { readFileSync } = require('fs'); |
| 102 | +
|
| 103 | + const privateKey = readFileSync('path/to/privateKey', 'utf-8'); |
| 104 | +
|
| 105 | + // NOTE if your privateKey also requires a passphrase provide it |
| 106 | +
|
| 107 | + const connection = new Connection({ |
| 108 | + transport: 'ssh', |
| 109 | + transportOptions: { host: 'myhost', username: 'myuser', privateKey, passphrase: 'myphrase' } |
| 110 | + }); |
| 111 | +
|
| 112 | +Creating a ``Connection`` using the ``idb`` tranport. |
| 113 | + |
| 114 | +.. code-block:: js |
| 115 | +
|
| 116 | + const connection = new Connection({ |
| 117 | + transport: 'idb', |
| 118 | + transportOptions: { database: '*LOCAL', username: 'myuser', password: 'mypass' } |
| 119 | + }); |
| 120 | +
|
| 121 | +Creating a ``Connection`` using the ``REST`` tranport. |
| 122 | + |
| 123 | +.. code-block:: js |
| 124 | +
|
| 125 | + const connection = new Connection({ |
| 126 | + transport: 'rest', |
| 127 | + transportOptions: { |
| 128 | + host: 'myhost', |
| 129 | + database: '*LOCAL', |
| 130 | + username: 'myuser', |
| 131 | + password: 'mypass' |
| 132 | + port: 80, |
| 133 | + path:'/cgi-bin/xmlcgi.pgm', |
| 134 | + } |
| 135 | + }); |
0 commit comments