Follow the steps below to try Pegasus quickly and get a basic idea of how it works:
Pegasus uses Gradle as the build system. The following points summarize some basic tasks you can do:
Build (implies test)
Generate and clean IntelliJ IDEA project stub
./gradlew idea ./gradlew cleanIdea
Generate and clean Eclipse project stub
./gradlew eclipse ./gradlew cleanEclipse
Tasks can be executed on a per-module basis. For example, do this to only build the restli-server and its dependencies:
Pegasus comes with a set of examples to illustrate how the server and client interact. We have created Gradle tasks to run the server and client. There are 4 variants; all of them reside in restli-example-server and restli-example-client modules:
To start, run the basic example server by doing this:
The build will be paused after printing “Basic example server running on port 7279. Press any key to stop server.” until you hit return. To quickly verify, use cURL as:
You should see a JSON object with some “photo” information. Do this to run the client:
The client will make a variety of requests to the server, print informative messages, and then shutdown. Each time, the result may be slightly different.
To use the D2 variants, you need ZooKeeper 3.3.4 and upward to be downloaded and running on port 2121. Before starting the server, some D2 related data must be initialized in ZooKeeper with D2ConfigDiscovery:
The D2 example server and client are started by this:
./gradlew startExampleD2Server ./gradlew startExampleD2Client
The client should successfully retrieve some “album” information from server and intentionally make a bad request to retrieve a non-existent photo, followed by a stack trace.
Throughout the examples, we can frequently see “photo” and “album” objects. These data schemas are defined in the restli-example-api module. API module are the interface modules with contents shared by or exchanged between the server and client. Generally speaking, we usually put 3 kinds of files in API:
Pegasus comes with many code generators:
You can find example Gradle scripts of how to call the generators in the build_script directory.