Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

thrift

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thrift

node.js bindings for the Apache Thrift RPC system

  • 0.14.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
238K
decreased by-4.99%
Maintainers
4
Weekly downloads
 
Created

What is thrift?

The thrift npm package is a JavaScript implementation of the Apache Thrift framework, which is used for scalable cross-language services development. Thrift allows you to define data types and service interfaces in a simple definition file, and it generates code to be used across multiple languages. This makes it easier to build and maintain services that communicate across different programming languages.

What are thrift's main functionalities?

Defining a Thrift Service

This code demonstrates how to define a Thrift service in Node.js. The service is defined in a Thrift IDL file, which is then compiled to generate the necessary JavaScript files. The server listens on port 9090 and implements a method called `myMethod`.

const thrift = require('thrift');
const MyService = require('./gen-nodejs/MyService');
const ttypes = require('./gen-nodejs/my_types');

const server = thrift.createServer(MyService, {
  myMethod: function(arg, result) {
    console.log('myMethod called with:', arg);
    result(null, 'response');
  }
});

server.listen(9090);

Creating a Thrift Client

This code demonstrates how to create a Thrift client in Node.js. The client connects to the Thrift server running on localhost at port 9090 and calls the `myMethod` function, passing an argument and handling the response.

const thrift = require('thrift');
const MyService = require('./gen-nodejs/MyService');

const connection = thrift.createConnection('localhost', 9090);
const client = thrift.createClient(MyService, connection);

client.myMethod('argument', (err, response) => {
  if (err) {
    console.error(err);
  } else {
    console.log('Response:', response);
  }
  connection.end();
});

Defining Thrift Data Types

This Thrift IDL file defines a data structure `MyStruct` and a service `MyService` with a method `myMethod` that takes `MyStruct` as an argument. This file is used to generate the necessary code for both the client and server.

namespace js MyService

struct MyStruct {
  1: i32 id,
  2: string name
}

service MyService {
  string myMethod(1: MyStruct myStruct)
}

Other packages similar to thrift

FAQs

Package last updated on 08 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc