Ejemplo n.º 1
0
        private async Task <T> RequestAsync <T>(HttpMethod httpMethod, string path, NexusRequest request, CancellationToken token, bool logOutput)
        {
            token.ThrowIfCancellationRequested();

            var requestName = typeof(T).Name;
            var logHeader   = $"API {(httpMethod == HttpMethod.Get ? "GET" : "POST")} {path}:";

            try
            {
                if (path == null)
                {
                    _log.LogError($"Path is missing for '{requestName}' get request");
                    return(default);
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> PostAsync(string path, string logHeader, NexusRequest request, CancellationToken token, bool logOutput)
        {
            var form = new FormUrlEncodedContent(request?.Param ?? null);

            if (_log != null && logOutput)
            {
                _log.LogInformation($"{logHeader} {await form.ReadAsStringAsync()}");
            }

            return(await _client.PostAsync(path, form, token).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
 protected Task <T> PostAsync <T>(string path, NexusRequest request, CancellationToken token = default, bool logOutput = true)
 {
     return(RequestAsync <T>(HttpMethod.Post, path, request, token, logOutput));
 }
Ejemplo n.º 4
0
        public async Task <HttpResponseMessage> GetAsync(string path, string logHeader, NexusRequest request, CancellationToken token, bool logOutput)
        {
            var getRequest = request != null
                ? $"{path}?{request.GetParamString()}"
                : path;

            if (_log != null && logOutput)
            {
                _log.LogInformation($"{logHeader} {getRequest}");
            }

            return(await _client.GetAsync(getRequest, token));
        }