示例#1
0
        public async Task OnGetAsync(Guid id)
        {
            _logger.LogInformation("Fetching item {ID}", id);

            Item = await _http.SendAsync <ToDoItem>(HttpMethod.Get, $"/todo/{id}");

            ViewData["Title"] = $"{Item.Title} - ToDo";
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                _logger.LogWarning("Model state is not valid");

                return(Page());
            }

            _logger.LogInformation("Creating new item");

            await _http.SendAsync(HttpMethod.Post, "/todo", Item);

            return(RedirectToPage("./Index"));
        }
示例#3
0
        public async Task OnGetAsync()
        {
            _logger.LogInformation("Fetching all items");

            Items = await _http.SendAsync <IList <ToDoItem> >(HttpMethod.Get, "/todo");
        }
        /// <summary>
        /// Sends an HTTP POST request and receives a response with payload of type <typeparamref name="TResult"/>.
        /// </summary>
        /// <param name="client">The <see cref="IHttpRestClient" />.</param>
        /// <param name="path">The path to be requested.</param>
        /// <param name="query">The querystring of the request.</param>
        /// <typeparam name="TResult">The type to deserialize the response into.</typeparam>
        /// <returns>If successful, it returns an instance of <typeparamref name="TResult"/>, otherwise it throws a <see cref="HttpException"/>.</returns>
        public static Task <TResult> PostAsync <TResult>(this IHttpRestClient client, string path, IQueryString?query = null)
        {
            _ = client ?? throw new ArgumentNullException(nameof(client));

            return(client.SendAsync <TResult>(HttpMethod.Post, path, query));
        }
        /// <summary>
        /// Sends an HTTP GET request with payload of type <typeparamref name="TContent"/>.
        /// </summary>
        /// <param name="client">The <see cref="IHttpRestClient" />.</param>
        /// <param name="path">The path to be requested.</param>
        /// <param name="content">The payload of the request.</param>
        /// <param name="query">The querystring of the request.</param>
        /// <typeparam name="TContent">The type of the payload of the request.</typeparam>
        /// <returns>If unsuccessful, it throws a <see cref="HttpException"/>.</returns>
        public static Task GetAsync <TContent>(this IHttpRestClient client, string path, TContent content, IQueryString?query = null)
        {
            _ = client ?? throw new ArgumentNullException(nameof(client));

            return(client.SendAsync <TContent>(HttpMethod.Get, path, content, query));
        }
        /// <summary>
        /// Sends an HTTP DELETE request with no payload on both request and response.
        /// </summary>
        /// <param name="client">The <see cref="IHttpRestClient" />.</param>
        /// <param name="path">The path to be requested.</param>
        /// <param name="query">The querystring of the request.</param>
        /// <returns>If unsuccessful, it throws a <see cref="HttpException"/>.</returns>
        public static Task DeleteAsync(this IHttpRestClient client, string path, IQueryString?query = null)
        {
            _ = client ?? throw new ArgumentNullException(nameof(client));

            return(client.SendAsync(HttpMethod.Delete, path, query));
        }