You can customize a Kepler service by overriding the default status codes, using attributes to specify HTTP verbs, and modifying REST responses. The following information illustrates how to implement these and other customizations to your Kepler service.
This page contains the following information:
You can set the X-CSRF-Header to any value except an empty string. Some HTTP clients and web browsers remove this header if it isn't set. See the following example:
x-CSRF-Header: -
Note: In general, the header value is set to a dash (-). Don't leave this header value blank.
To make Kepler service calls, you must include the X-CSRF-header as illustrated in the following samples:
HttpClient client = new HTTPClient(); client.DefaultRequestHeaders.Add("X-CSRF-Header", "-");
Note: The X-CSRF-Header is automatically applied when you use the .Net proxy to make calls to Kepler services. For more information, see Client .NET proxy.
REST call via JavaScript
requestOptions = {} requestOptions["X-CSRF-Header"] = "-"
The Kepler framework uses C# attributes to specify the HTTP verb associated with service endpoints. By default, an undecorated service method uses the POST verb. For more information, see Attributes (C#) on the Microsoft website, and HTTP method requests on MDN web docs.
The Kepler framework makes the following verbs available in the Relativity.Kepler.Services namespace:
The following code sample illustrates how to use of an HTTP verb attribute.
using Relativity.Kepler.Services; // Service contract namespace Product.Feature.Service { [WebService("MyKeplerService")] [ServiceAudience(Audience.Public)] public interface IExampleService : IDisposable { [HttpGet] Task<bool> PingAsync(); [HttpDelete] Task DeleteAsync(int artifactID); } }
In a Kepler service, you can control status codes as follows:
[HttpSuccessStatusCode(System.Net.HttpStatusCode.Created)] Task<MyModel> DoAsync();
[FaultCode(HttpStatusCode.Ambiguous)] public class MyCustomException : ServiceException { }
public async Task<IKeplerStream> DownloadStream() { Stream s = new MemoryStream(TEST_BYTES); return await Task.FromResult(new KeplerStream(s) { StatusCode = HttpStatusCode.Accepted }); }
private IResponseController _response; public TestService(IResponseController responseController) { _response = responseController; } public Task ModifyStatusCode() { _response.StatusCode = HttpStatusCode.Accepted; return Task.CompletedTask; }
You can use the ResponseController class to customize the REST response for a service request. The Kepler framework injects a new ResponseController object into the service constructor each time a call is made to that service. You can then use it to alter the HTTP status code or header information as illustrated in the following samples. For more information, see Client-side interactions with a Kepler serviceand Status Codes.
private IResponseController _response; public TestService(IResponseController responseController) { _response = responseController; } public Task ModifyStatusCode() { _response.StatusCode = HttpStatusCode.Accepted; return Task.CompletedTask; }
private IResponseController _response; public TestService(IResponseController responseController) { _response = responseController; } public Task ModifyHeader() { _response.Headers.Add("MyTestHeader", "MyValue"); return Task.CompletedTask; }
The Kepler framework handles localization through the ActiveCulture property of the ServiceFactory class class. This property references a CultureInfo object, which the consumer uses to specify a language code in HTTP requests. For more information, see CultureInfo Class on the Microsoft website.
Note: While the Accept-Language header can specify multiple languages, you can only set a single language through the ServiceFactory object. This practice avoids the possibilty of content negotiation by the server and makes the language used by both parties unambiguous.
... ServiceFactorySettings settings = new ServiceFactorySettings(relativityServicesUri, relativityRestUri, credentials); ServiceFactory factory = new ServiceFactory(settings); // Specify culture or language. factory.ActiveCulture = new CultureInfo("fr-FR"); // Create proxy to for the sample Kepler service. IExampleService proxy = factory.CreateProxy<IExampleService>(); // Outbound calls now sent with header: Accept-Language: fr-FR
Query parameters are key-value pairs added to the of a URL to refine a request when sorting, filtering, paging, or performing other actions. For more information, see Query Parameters on MDN web docs.
Use the following guidelines when query parameters with Kepler services:
The following code sample illustrates an endpoint on a Kepler service, which has query parameters.
// Specify qQuery parameters by adding a question mark (?). // Specify the default value in the endpoint method. // http://.../Product.Feature.Service.IExampleModule/MyKeplerService/ResouceType/22 // Returns an array of 10 ResponseDTOs indexed 0-9. // http://.../Product.Feature.Service.IExampleModule/MyKeplerService/ResouceType/22?firstIndex=20&lastIndex=29 // Returns an array of 10 ResponseDTOs indexed 20-29. [HttpGet] [Route("ResouceType/{resourceType}?{firstIndex}&{lastIndex"})] public Task<ResponseDTO[]> RequestResourceAsync(int resourceType, int firstIndex = 0, int lastIndex = 9) { ... }
Community Updates |
|||
Aero Developer FAQ | Evolving the Platform | Most recent release notes | |
Learn more | Learn more | Learn more |
Additional Resources |
|||
![]() |
![]() |
||
Access Third-Party Tools with GitHub | Create .NET Apps Faster with NuGet | ||
Visit github | visit nuget |