Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Blazor WebAssembly by Example

You're reading from   Blazor WebAssembly by Example A project-based guide to building web apps with .NET, Blazor WebAssembly, and C#

Arrow left icon
Product type Paperback
Published in Jul 2021
Publisher Packt
ISBN-13 9781800567511
Length 266 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Toi B. Wright Toi B. Wright
Author Profile Icon Toi B. Wright
Toi B. Wright
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Chapter 1: Introduction to Blazor WebAssembly 2. Chapter 2: Building Your First Blazor WebAssembly Application FREE CHAPTER 3. Chapter 3: Building a Modal Dialog Using Templated Components 4. Chapter 4: Building a Local Storage Service Using JavaScript Interoperability (JS Interop) 5. Chapter 5: Building a Weather App as a Progressive Web App (PWA) 6. Chapter 6: Building a Shopping Cart Using Application State 7. Chapter 7: Building a Kanban Board Using Events 8. Chapter 8: Building a Task Manager Using ASP.NET Web API 9. Chapter 9: Building an Expense Tracker Using the EditForm Component 10. Other Books You May Enjoy

Using the HttpClient service

HTTP is not just for serving web pages – it can also be used for serving data. These are the HTTP methods that we will be using in this chapter:

  • GET: This method is used to request one or more resources.
  • POST: This method is used to create a new resource.
  • PUT: This method is used to update a specified resource.
  • DELETE: This method is used to delete a specified resource.

The HttpClient service is a preconfigured service for making HTTP requests from a Blazor WebAssembly app. It is configured in the Program.cs file. The following code is used to configure it:

builder.Services.AddScoped(sp => new HttpClient {
  BaseAddress = new
    Uri(builder.HostEnvironment.BaseAddress) 
});

The HttpClient service is added to a page using dependency injection (DI). To use the HttpClient service in a component, you must inject it by either using the @inject directive or the Inject attribute. For more...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime