Follow the steps below to try Rest.li quickly and get a basic idea of how it works:
Rest.li uses Gradle as the build system. The following points summarize some basic tasks that can be run:
Build (implies test)
./gradlew build
Test
./gradlew test
Clean
./gradlew clean
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:
./gradlew :restli-server:build
Rest.li comes with a set of examples to illustrate how the server and client interact. Rest.Li provides 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:
./gradlew startExampleBasicServer
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:
curl http://localhost:7279/photos/1
You should see a JSON object with some “photo” information. Do this to run the client:
./gradlew startExampleBasicClient
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:
./gradlew exampleConfigDiscovery
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:
restspec.json
files are generated from resource classes using the com.linkedin.restli.tools.idlgen.RestLiResourceModelExporterCmdLineApp class..restspec.json
files. These builder classes provide convenient methods to construct Rest.li requests with various parameters.You can find example Gradle scripts of how to call the generators in the build_script directory.