Tutorial¶
Install Apache Thrift
Many Linux distributions have Apache Thrift packaged in their repositories and these packages should be preferred.
MacOS users can use package managers like Homebrew to install Thrift.
Windows users can download the compiler from our download page.
Manual Installation
Alternatively, you can build Thrift from source. Follow our building from source guide.
Writing a .thrift file
After the compiler is installed you will need to create a .thrift file. This file is an interface definition made up of Thrift types and Services. The services you define in this file are implemented by the server and are called by any clients.
In this tutorial, we’ll be using tutorial.thrift and shared.thrift.
Generate Source Code
The Thrift compiler is used to compile your Thrift file into source code used by your server code and client libraries.
thrift --gen <language> tutorial.thrift
To recursively compile all files imported by a Thrift file, run:
thrift -r --gen <language> tutorial.thrift
The sample tutorial.thrift file defines a basic calculator service, which includes another file called shared.thrift. Both files will be used to demonstrate how to build a Thrift client and server pair.
Language specific implementations of this tutorial can be found on Github.