/// <summary> /// Post a single document with the possibility to specify a different type /// for the new document object returned in the response. /// </summary> /// <typeparam name="T">The type of the post object used to record a new document.</typeparam> /// <typeparam name="U">Type of the returned document, only applies when /// <see cref="PostDocumentsQuery.ReturnNew"/> or <see cref="PostDocumentsQuery.ReturnOld"/> /// are used.</typeparam> /// <param name="collectionName"></param> /// <param name="document"></param> /// <param name="query"></param> /// <param name="serializationOptions">The serialization options. When the value is null the /// the serialization options should be provided by the serializer, otherwise the given options should be used.</param> /// <returns></returns> public virtual async Task <PostDocumentResponse <U> > PostDocumentAsync <T, U>( string collectionName, T document, PostDocumentsQuery query = null, ApiClientSerializationOptions serializationOptions = null) { string uriString = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uriString += "?" + query.ToQueryString(); } var content = GetContent(document, serializationOptions); using (var response = await _client.PostAsync(uriString, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostDocumentResponse <U> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// POST a js-transaction to ArangoDB. /// </summary> /// <remarks> /// https://www.arangodb.com/docs/stable/http/transaction-js-transaction.html /// </remarks> /// <typeparam name="T">Type to use for deserializing the object returned by the transaction function.</typeparam> /// <param name="body">Object containing information to submit in the POST transaction request.</param> /// <returns>Response from ArangoDB after processing the request.</returns> public virtual async Task <PostTransactionResponse <T> > PostTransactionAsync <T>( PostTransactionBody body) { var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_transactionApiPath, content).ConfigureAwait(false)) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(DeserializeJsonFromStream <PostTransactionResponse <T> >(stream)); } var error = DeserializeJsonFromStream <ApiErrorResponse>(stream); throw new ApiErrorException(error); } }
/// <summary> /// Gets a JSON Web Token generated by the ArangoDB server. /// </summary> /// <param name="body">Object containing username and password.</param> /// <returns>Object containing the encoded JWT token value.</returns> public async Task <JwtTokenResponse> GetJwtTokenAsync(JwtTokenRequestBody body) { byte[] content = GetContent(body, true, false); using (var response = await _client.PostAsync("/_open/auth", content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <JwtTokenResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Create a new AQL user function. /// POST /_api/aqlfunction /// </summary> /// <param name="body">The body of the request containing required properties.</param> /// <returns></returns> public virtual async Task <PostAqlFunctionResponse> PostAqlFunctionAsync(PostAqlFunctionBody body) { var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PostAsync(_apiPath, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostAqlFunctionResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Creates a new database. /// (Only possible from within the _system database) /// </summary> /// <param name="request">The parameters required by this endpoint.</param> /// <returns></returns> public async Task <PostDatabaseResponse> PostDatabaseAsync(PostDatabaseBody request) { var content = GetStringContent(request, true, true); using (var response = await _client.PostAsync(_databaseApiPath, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostDatabaseResponse>(stream)); } throw await GetApiErrorException(response); } }
public async Task <CursorResponse <T> > PostCursorAsync <T>(PostCursorBody cursorRequest) { var content = GetStringContent(cursorRequest, true, true); using (var response = await _client.PostAsync(_cursorApiPath, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <CursorResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Creates a new database. /// (Only possible from within the _system database) /// </summary> /// <param name="request">The parameters required by this endpoint.</param> /// <returns></returns> public virtual async Task <PostDatabaseResponse> PostDatabaseAsync(PostDatabaseBody request) { var content = GetContent(request, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_databaseApiPath, content).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return(DeserializeJsonFromStream <PostDatabaseResponse>(stream)); } throw await GetApiErrorException(response).ConfigureAwait(false); } }
/// <summary> /// Creates a new graph in the graph module. /// POST /_api/gharial /// </summary> /// <param name="postGraphBody">The information of the graph to create.</param> /// <returns></returns> public async Task <PostGraphResponse> PostGraphAsync( PostGraphBody postGraphBody, PostGraphQuery query = null) { string uri = _graphApiPath; if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(postGraphBody, true, true); using (var response = await _transport.PostAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostGraphResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Creates a new graph in the graph module. /// </summary> /// <param name="postGraphBody">The information of the graph to create.</param> /// <returns></returns> public async Task <PostGraphResponse> PostGraph(PostGraphBody postGraphBody) { var content = GetStringContent(postGraphBody, true, true); using (var response = await _transport.PostAsync(_graphApiPath, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostGraphResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Execute an AQL query, creating a cursor which can be used to page query results. /// </summary> /// <param name="postCursorBody">Object encapsulating options and parameters of the query.</param> /// <returns></returns> public virtual async Task <CursorResponse <T> > PostCursorAsync <T>( PostCursorBody postCursorBody) { var content = GetContent(postCursorBody, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_cursorApiPath, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <CursorResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Execute an AQL query, creating a cursor which can be used to page query results. /// </summary> /// <param name="postCursorBody">Object encapsulating options and parameters of the query.</param> /// <param name="headerProperties">Optional. Additional Header properties.</param> /// <returns></returns> public virtual async Task <CursorResponse <T> > PostCursorAsync <T>( PostCursorBody postCursorBody, CursorHeaderProperties headerProperties = null) { var content = GetContent(postCursorBody, new ApiClientSerializationOptions(true, true)); var headerCollection = GetHeaderCollection(headerProperties); using (var response = await _client.PostAsync(_cursorApiPath, content, headerCollection).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return(DeserializeJsonFromStream <CursorResponse <T> >(stream)); } throw await GetApiErrorException(response).ConfigureAwait(false); } }
public async Task <PostCollectionResponse> PostCollectionAsync(PostCollectionBody body, PostCollectionQuery options = null) { string uriString = _collectionApiPath; if (options != null) { uriString += "?" + options.ToQueryString(); } var content = GetContent(body, true, true); using (var response = await _transport.PostAsync(uriString, content)) { var stream = await response.Content.ReadAsStreamAsync(); if (response.IsSuccessStatusCode) { return(DeserializeJsonFromStream <PostCollectionResponse>(stream)); } throw await GetApiErrorException(response); } }