예제 #1
0
        public async Task <bool> Delete(ArticleId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));
            _logger.LogTrace($"{nameof(Delete)}: Id={id}");

            HttpResponseMessage response = await _httpClient.DeleteAsync($"api/article/{id.ToBase64()}", token);

            return(response.StatusCode switch
            {
                HttpStatusCode.OK => true,
                HttpStatusCode.NotFound => false,

                _ => throw new HttpRequestException($"Invalid http code={response.StatusCode}"),
            });
예제 #2
0
        public async Task <ArticlePayload?> Get(ArticleId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));
            _logger.LogTrace($"{nameof(Get)}: Id={id}");

            try
            {
                return(await _httpClient.GetFromJsonAsync <ArticlePayload?>($"api/article/{id.ToBase64()}", token));
            }
            catch (HttpRequestException ex)
            {
                _logger.LogError(ex, $"{nameof(Get)}: id={id} failed");
                return(null);
            }
        }