Last date modified: 2025-Oct-16
Relativity.API.Extensions
The Relativity.API.Extensions library provides additional helper functions that will be useful when interacting with RelativityOne environments in the cloud-based infrastructure. You can use the helper functions in this library to set up calls to REST services in a specific environment.
- GetInstanceBaseURL - Allows you to build URLs to any API without assuming the host name. Use this method to safeguard your application against backend URL changes in the RelativityOne infrastructure.
- BuildHTTPAuthorizationHeader - Allows populating the Authentication header on HTTP requests. Use this method to safeguard your application against backend authentication/authorization changes in RelativityOne.
While this is a new API focused more on interacting with RelativityOne through REST services, you can also continue to use the ServiceFactory, which provides the same benefits for consumers of RelativityOne .NET API client libraries.
Relativity API Extensions .NET API Reference
Usage Examples
The code sample below illustrates how to use the GetInstanceBaseURL and BuildHTTPAuthorizationHeader methods to construct a HTTP service call (you will need to reference Relativity.API.Extensions.dll in your project).
using Relativity.API.Extensions;
public class AgentBaseTest : AgentBase
{
private IServicesMgr _servicesMgr;
public AgentBaseTest()
{
}
public override string Name => "AgentBaseTest";
public override void Execute()
{
_servicesMgr = Helper.GetServicesManager();
var client = HttpClientFactory.CreateClient(_servicesMgr, ExecutionIdentity.CurrentUser);
var requestUrl = GetRequestUrl("/api/test-endpoint");
var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
var response = client.SendAsync(request).Result;
}
private Uri GetRequestUrl(string requestEndpoint)
{
var baseUrl = _servicesMgr.GetInstanceBaseURL();
if (string.IsNullOrEmpty(baseUrl))
{
throw new InvalidOperationException("Base URL is not set.");
}
var fullUri = new Uri(new Uri(baseUrl), requestEndpoint);
return fullUri;
}
}
public class HttpClientFactory
{
private static Lazy<HttpClientHandler> _sharedHandler => new Lazy<HttpClientHandler>();
public static HttpClient CreateClient(IServicesMgr servicesMgr, ExecutionIdentity identity)
{
if (servicesMgr == null)
throw new ArgumentNullException(nameof(servicesMgr));
var handler = new AuthDelegatingHandler(servicesMgr, identity)
{
InnerHandler = _sharedHandler.Value
};
return new HttpClient(handler, disposeHandler: false);
}
}
public class AuthDelegatingHandler : DelegatingHandler
{
private IServicesMgr _servicesMgr;
private ExecutionIdentity _identity;
public AuthDelegatingHandler(IServicesMgr servicesMgr, ExecutionIdentity identity)
{
_servicesMgr = servicesMgr;
_identity = identity;
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Contains("Authorization")) return base.SendAsync(request, cancellationToken);
// Set Authorization header
var authorizationHeader = _servicesMgr.BuildHTTPAuthorizationHeader(_identity);
if (!string.IsNullOrWhiteSpace(authorizationHeader))
{
request.Headers.Add("Authorization", authorizationHeader);
}
return base.SendAsync(request, cancellationToken);
}
}
FAQs
The methods are applicable whenever you build your own http request using HttpClient. They also apply if you generate your own client library from our OpenAPI specification (OAS) files.
We highly recommend using these methods to safeguard your code from backend infrastructure changes in RelativityOne.
If your code uses our .NET SDKs and the ServiceFactory, your code is already insulated from change. If you are manually constructing http requests (and setting the service URL and authentication headers), your application may stop working in the future if you aren’t using these methods to build your requests.
Version History
Release Notes
- Updates to the package README file
Supported Relativity Version Range
| Lowest Version | Highest Version |
|---|---|
| 25.10.7.2 | Unreleased |
Release Notes
- Remove dependency on Relativity.Logging
- Update Relativity.API minimum dependency version to v20.0.0
Supported Relativity Version Range
| Lowest Version | Highest Version |
|---|---|
| 25.10.7.2 | Unreleased |
Release Notes
- Initial Version
Supported Relativity Version Range
| Lowest Version | Highest Version |
|---|---|
| Unreleased | Unreleased |
On this page