Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide response headers to all API methods #469

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arangodb-net-standard.Test/ViewApi/ViewApiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public async Task GetAllViewsAsync_ShouldSucceed()
});
var res = await _viewApi.GetAllViewsAsync();

Assert.Equal(HttpStatusCode.OK, res.Code);
Assert.False(res.Error);
Assert.NotNull(res.Result);
Assert.NotEmpty(res.Result);
Assert.Equal(HttpStatusCode.OK, res.Response.Code);
Assert.False(res.Response.Error);
Assert.NotNull(res.Response.Result);
Assert.NotEmpty(res.Response.Result);
}

[Fact]
Expand Down
40 changes: 24 additions & 16 deletions arangodb-net-standard/AdminApi/AdminApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ public AdminApiClient(IApiClientTransport client, IApiClientSerialization serial
/// </summary>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#read-global-logs-from-the-server
/// </remarks>
public virtual async Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = null, CancellationToken token = default)
public virtual async Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/log/entries";
if (query != null)
{
uri += '?' + query.ToQueryString();
}
using (var response = await _client.GetAsync(uri, null, token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -80,17 +81,18 @@ public virtual async Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = nul
/// Reloads the routing table.
/// POST /_admin/routing/reload
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#reloads-the-routing-information
/// </remarks>
public virtual async Task<bool> PostReloadRoutingInfoAsync(CancellationToken token = default)
public virtual async Task<bool> PostReloadRoutingInfoAsync(ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/routing/reload";
var body = new byte[] { };
using (var response = await _client.PostAsync(uri, body, null, token).ConfigureAwait(false))
using (var response = await _client.PostAsync(uri, body, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -105,16 +107,17 @@ public virtual async Task<bool> PostReloadRoutingInfoAsync(CancellationToken tok
/// The method will fail if the server is not running in cluster mode.
/// GET /_admin/server/id
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#return-id-of-a-server-in-a-cluster
/// </remarks>
public virtual async Task<GetServerIdResponse> GetServerIdAsync(CancellationToken token = default)
public virtual async Task<GetServerIdResponse> GetServerIdAsync(ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/server/id";
using (var response = await _client.GetAsync(uri, null, token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -129,16 +132,17 @@ public virtual async Task<GetServerIdResponse> GetServerIdAsync(CancellationToke
/// Retrieves the role of the server in a cluster.
/// GET /_admin/server/role
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#return-the-role-of-a-server-in-a-cluster
/// </remarks>
public virtual async Task<GetServerRoleResponse> GetServerRoleAsync(CancellationToken token = default)
public virtual async Task<GetServerRoleResponse> GetServerRoleAsync(ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/server/role";
using (var response = await _client.GetAsync(uri, null, token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -153,16 +157,17 @@ public virtual async Task<GetServerRoleResponse> GetServerRoleAsync(Cancellation
/// Retrieves the server database engine type.
/// GET /_api/engine
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/miscellaneous-functions.html#return-server-database-engine-type
/// </remarks>
public virtual async Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(CancellationToken token = default)
public virtual async Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = "_api/engine";
using (var response = await _client.GetAsync(uri, null, token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -178,20 +183,21 @@ public virtual async Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(
/// GET /_api/version
/// </summary>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/miscellaneous-functions.html#return-server-version
/// </remarks>
public virtual async Task<GetServerVersionResponse> GetServerVersionAsync(GetServerVersionQuery query = null, CancellationToken token = default)
public virtual async Task<GetServerVersionResponse> GetServerVersionAsync(GetServerVersionQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = "_api/version";
if (query != null)
{
uri += '?' + query.ToQueryString();
}
using (var response = await _client.GetAsync(uri,null,token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -206,16 +212,17 @@ public virtual async Task<GetServerVersionResponse> GetServerVersionAsync(GetSer
/// Retrieves the server license information.
/// GET /_admin/license
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/3.9/administration-license.html
/// </remarks>
public virtual async Task<GetLicenseResponse> GetLicenseAsync(CancellationToken token = default)
public virtual async Task<GetLicenseResponse> GetLicenseAsync(ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/license";
using (var response = await _client.GetAsync(uri, token: token).ConfigureAwait(false))
using (var response = await _client.GetAsync(uri, headers?.ToWebHeaderCollection(), token: token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -232,21 +239,22 @@ public virtual async Task<GetLicenseResponse> GetLicenseAsync(CancellationToken
/// </summary>
/// <param name="licenseKey">The new license key</param>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/3.9/administration-license.html
/// </remarks>
public virtual async Task<PutLicenseResponse> PutLicenseAsync(string licenseKey, PutLicenseQuery query = null, CancellationToken token = default)
public virtual async Task<PutLicenseResponse> PutLicenseAsync(string licenseKey, PutLicenseQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default)
{
string uri = $"{_adminApiPath}/license";
if (query != null)
{
uri += '?' + query.ToQueryString();
}
var content = await GetContentAsync(licenseKey, new ApiClientSerializationOptions(true, true));
using (var response = await _client.PutAsync(uri, content, token: token).ConfigureAwait(false))
using (var response = await _client.PutAsync(uri, content, headers?.ToWebHeaderCollection(), token: token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand Down
26 changes: 17 additions & 9 deletions arangodb-net-standard/AdminApi/IAdminApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,100 +16,108 @@ public interface IAdminApiClient
/// Works on ArangoDB 3.8 or later.
/// </summary>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#read-global-logs-from-the-server
/// </remarks>
Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = null, CancellationToken token = default);
Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Reloads the routing table.
/// POST /_admin/routing/reload
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#reloads-the-routing-information
/// </remarks>
Task<bool> PostReloadRoutingInfoAsync(CancellationToken token = default);
Task<bool> PostReloadRoutingInfoAsync(ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Retrieves the internal id of the server.
/// The method will fail if the server is not running in cluster mode.
/// GET /_admin/server/id
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#return-id-of-a-server-in-a-cluster
/// </remarks>
Task<GetServerIdResponse> GetServerIdAsync(CancellationToken token = default);
Task<GetServerIdResponse> GetServerIdAsync(ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Retrieves the role of the server in a cluster.
/// GET /_admin/server/role
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#return-the-role-of-a-server-in-a-cluster
/// </remarks>
Task<GetServerRoleResponse> GetServerRoleAsync(CancellationToken token = default);
Task<GetServerRoleResponse> GetServerRoleAsync(ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Retrieves the server database engine type.
/// GET /_api/engine
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/miscellaneous-functions.html#return-server-database-engine-type
/// </remarks>
Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(CancellationToken token = default);
Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Retrieves the server version.
/// GET /_api/version
/// </summary>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/stable/http/miscellaneous-functions.html#return-server-version
/// </remarks>
Task<GetServerVersionResponse> GetServerVersionAsync(GetServerVersionQuery query = null, CancellationToken token = default);
Task<GetServerVersionResponse> GetServerVersionAsync(GetServerVersionQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Retrieves the server license information.
/// GET /_admin/license
/// </summary>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/3.9/administration-license.html
/// </remarks>
Task<GetLicenseResponse> GetLicenseAsync(CancellationToken token = default);
Task<GetLicenseResponse> GetLicenseAsync(ApiHeaderProperties headers = null, CancellationToken token = default);

/// <summary>
/// Sets a new license key.
/// PUT /_admin/license
/// </summary>
/// <param name="licenseKey">The new license key</param>
/// <param name="query">Query string parameters</param>
/// <param name="headers">Headers for the request</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
/// <remarks>
/// For further information see
/// https://www.arangodb.com/docs/3.9/administration-license.html
/// </remarks>
Task<PutLicenseResponse> PutLicenseAsync(string licenseKey, PutLicenseQuery query = null, CancellationToken token = default);
Task<PutLicenseResponse> PutLicenseAsync(string licenseKey, PutLicenseQuery query = null, ApiHeaderProperties headers = null, CancellationToken token = default);
}
}
Loading