node-thrift-express
v1.0.6
Published
node-thrift-express automates the creation of Express endpoints for Thrift functionality in a Node server. The module uses the generated Node client stubs to generate an endpoint for every function defined in the Thrift definition file. ## installation
Downloads
2
Readme
node-thrift-express
node-thrift-express automates the creation of Express endpoints for Thrift functionality in a Node server. The module uses the generated Node client stubs to generate an endpoint for every function defined in the Thrift definition file.
installation
npm install node-thrift-express
usage
After installing the module, the file config.js
(shown below) in the /node-thrift-express
folder in /node_modules
must be edited.
const servicePath = require('');
const ttypesPath = require('');
const serviceHost = '';
const servicePort = '';
const postPrefixes = [''];
module.exports = {
servicePath: servicePath,
ttypesPath: ttypesPath,
serviceHost: serviceHost,
servicePort: servicePort,
postPrefixes: postPrefixes
}
Setup
Enter the paths of the generated files (service file and types file) in your /gen-nodejs
directory. Then, enter the host and port of your Thrift server. Finally, enter the prefixes of all the functions you wish to assign a POST endpoint; these are all functions that create objects, so the prefixes could be 'Add' or 'Create', for example.
Make sure your parameter objects are create following a Request/Response pattern. The parameter object for the function AddUser()
must be named AddUserRequest
, so the name of the function + 'Request'. If the request objects have a different suffix, it can be changed in node-thrift-express.js
in line 32: var paramsName = name + 'Request';
The endpoints receive the same name as their function, for example /AddUser
.
Updating
If new Thrift functions are added to the definition file, simply generate the client stubs anew with $ thrift -r --gen js:node <directory/thriftfile.thrift>
. After that, the endpoints can be called immediately using the name of the function.