- clone the repository locally and move into directory
git clone https://github.com/mchen07/restli-csharp.git
cd restli-csharp
- run the gradle script to generate data templates:
- on Windows:
gradlew.bat clean build
- on Mac/Linux:
./gradlew clean build
- on Windows:
- open
restlicsharp.sln
in Visual Studio:- build the solution
- run all tests for the solution to ensure everything is setup
- note: all tests in
RestliClientIntegrationTests
may fail, as those tests assume there is a Rest.li server running athttp://localhost:1338
that supportsGET
,CREATE
, andFINDER
requests for thebasicCollection
resource; however, all other tests should pass
A good example of the different data template types can be found in the following places after you have generated the data templates:
- Record:
restlicsharpdata/restlidataintegration/generatedDataTemplate/com/linkedin/rest li/datagenerator/integration/SimpleRecord.cs
- Enum:
restlicsharpdata/restlidataintegration/generatedDataTemplate/com/linkedin/rest li/datagenerator/integration/TestEnum.cs
- Union:
restlicsharpdata/restlidataintegration/generatedDataTemplate/com/linkedin/rest li/datagenerator/integration/UnionTest.cs
- this data template is a Record class with a few Union classes defined inside it
Here is a snippet showing how you would use the client to issue a synchronous GET
request to a resource foo
for a Record Greeting
with integer ID 123
string urlPrefix = "http://hostname:port";
string baseTemplateUrl = "/foo";
RestClient client = new RestClient(urlPrefix);
GetRequestBuilder<int, Greeting> requestBuilder = new GetRequestBuilder<int, Greeting>(baseTemplateUrl);
requestBuilder.SetID(123);
GetRequest<int, Greeting> request = requestBuilder.Build();
EntityResponse<Greeting> response = client.RestRequestSync(request);
Greeting greeting = response.element;
Here is a snippet showing how you would use the client to issue the asynchronous analogue of the same request in the previous example
string urlPrefix = "http://hostname:port";
string baseTemplateUrl = "/foo";
RestClient client = new RestClient(urlPrefix);
GetRequestBuilder<int, Greeting> requestBuilder = new GetRequestBuilder<int, Greeting>(baseTemplateUrl);
requestBuilder.SetID(123);
GetRequest<int, Greeting> request = requestBuilder.Build();
RestliCallback<EntityResponse<Greeting>>.SuccessHandler successHandler = delegate (EntityResponse<Greeting> response)
{
Greeting greeting = response.element;
// Do something with `greeting` here
};
RestliCallback<EntityResponse<Greeting>> callback = new RestliCallback<EntityResponse<Greeting>>(successHandler);
client.RestRequestAsync(request, callback);