![]() | |
Original author(s) | Facebook, Inc. |
---|---|
Developer(s) | Apache Software Foundation |
Stable release | 0.18.1
/ 1 March 2023[1] |
Repository | Thrift Repository |
Written in | ActionScript, C, C#, C++, D, Dart, Delphi, Erlang, Go, Haskell, Haxe, Java, JavaScript, Node.js, OCaml, Perl, PHP, Python, Rust, Scala, Smalltalk |
Type | Remote procedure call framework |
License | Apache 2.0 |
Website | thrift |
Thrift is an interface definition language and binary communication protocol[2] used for defining and creating services for numerous programming languages.[3] It was developed at Facebook for "scalable cross-language services development" and as of 2020 is an open source project in the Apache Software Foundation.
With a remote procedure call (RPC) framework it combines a software stack with a code generation engine to build cross-platform services which can connect applications written in a variety of languages and frameworks, including ActionScript, C, C++,[4] C#, Cappuccino,[5] Cocoa, Delphi, Erlang, Go, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PHP, Python, Ruby, Elixir,[6] Rust, Scala, Smalltalk and Swift.[7] The implementation was described in an April 2007 technical paper released by Facebook, now hosted on Apache.[8][9]
Thrift includes a complete stack for creating clients and servers.[10] The top part is generated code from the Thrift definition. From this file, the services generate client and processor codes. In contrast to built-in types, created data structures are sent as a result of generated code. The protocol and transport layer are part of the runtime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure to tie protocols and transports together, like blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is implemented differently for different languages.
Thrift supports a number of protocols:[10]
The supported transports are:
ByteArrayOutputStream
internally.Thrift also provides a number of servers, which are
Some stated benefits of Thrift include:[12]
ArrayList<String>
. C++ uses std::vector<std::string>
.Thrift is written in C++, but can create code for a number of languages. To create a Thrift service, one has to write Thrift files that describe it, generate the code in the destination language, write some code to start the server, and call it from the client. Here is a code example of such a description file:
enum PhoneType {
HOME,
WORK,
MOBILE,
OTHER
}
struct Phone {
1: i32 id,
2: string number,
3: PhoneType type
}
service PhoneService {
Phone findById(1: i32 id),
list<Phone> findAll()
}
Thrift will generate the code out of this descriptive information. For instance, in Java, the PhoneType
will be a simple enum
inside the Phone
class.