Instant Download Beginning Azure Static Web Apps: Building and Deploying Dynamic Web Applications with Blazor 1st Edition Stacy Cashmore PDF All Chapters
Instant Download Beginning Azure Static Web Apps: Building and Deploying Dynamic Web Applications with Blazor 1st Edition Stacy Cashmore PDF All Chapters
com
https://ebookmeta.com/product/beginning-azure-static-web-
apps-building-and-deploying-dynamic-web-applications-with-
blazor-1st-edition-stacy-cashmore/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/microsoft-blazor-building-web-
applications-in-net-second-edition-peter-himschoot/
ebookmeta.com
https://ebookmeta.com/product/statecraft-and-the-political-economy-of-
capitalism-1st-edition-scott-g-nelson/
ebookmeta.com
Do Android Girls Need Oil Changes Vol 1 A. R. Cevlar
https://ebookmeta.com/product/do-android-girls-need-oil-changes-
vol-1-a-r-cevlar/
ebookmeta.com
https://ebookmeta.com/product/the-cambridge-handbook-of-material-
culture-studies-cambridge-handbooks-in-anthropology-lu-ann-de-cunzo/
ebookmeta.com
https://ebookmeta.com/product/the-four-pillars-of-investing-lessons-
for-building-a-winning-portfolio-2nd-edition-william-j-bernstein/
ebookmeta.com
https://ebookmeta.com/product/101-cases-in-respiratory-medicine-1st-
edition-supriya-sarkar/
ebookmeta.com
https://ebookmeta.com/product/the-psychology-of-dictatorship-1st-
edition-fathali-m-moghaddam/
ebookmeta.com
The Artist 1st Edition Sheri Lewis Wohl
https://ebookmeta.com/product/the-artist-1st-edition-sheri-lewis-wohl/
ebookmeta.com
Beginning Azure
Static Web Apps
Building and Deploying Dynamic
Web Applications with Blazor
Stacy Cashmore
Beginning Azure Static Web Apps: Building and Deploying Dynamic Web
Applications with Blazor
Stacy Cashmore
Amsterdam, The Netherlands
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
x
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 285
xi
About the Author
Speaker, author, and software developer, Stacy Cashmore
has been developing solutions since the mid-1990s in
various companies and industries ranging from facilitating
contract jobbing to allowing consumers to close a mortgage
without the help of a financial adviser – with lots in between.
She has a passion for sharing knowledge: using story telling
for sharing her experiences to help teams grow in the ways that
they develop software and work together and performing live
coding demonstrations to inspire others to try new technologies.
For her effort in the community, Stacy has been awarded the Microsoft MVP for
Developer Technologies since 2020.
xiii
About the Technical Reviewers
Marc Duiker is a Senior Developer Advocate at Ably with a
strong focus on event-driven architectures in the Azure cloud.
He loves helping developers to achieve more every day.
You might have seen Marc at a developer meetup
or conference since he's a regular speaker in the area of
Azure cloud and serverless technologies. He started Azure
Functions University, a free and open source learning
curriculum on GitHub, where everyone can learn about
Azure Functions at their own pace. In 2019, 2020, and
2021, Marc received the Microsoft Azure MVP award for his
community contributions.
In his spare time, Marc likes to give attention to the creative part of his brain. He likes
to create pixel art (check out VSCode Pets), code visuals and music, and an occasional
retro game.
xv
Acknowledgments
This book has been a while in the making. Not only the writing itself but also the journey
leading up to it. And there are many people to whom I owe a huge thank you.
I need to start with the amazing Jessica Engström. For your kindness to a terrified
conference attendee and starting me on this journey by convincing me to try my hand at
public speaking and for becoming an amazing friend.
To all the speakers from Swetugg 2019 for helping me get through that first talk, I’m
honored that I can call so many of you friends now.
And to Mattias Karlsson, for inviting me to write my first technical talk for your
conference in 2020. That really put me on the road to making technical content and
looking at new technologies – even if Covid got in the way and it had to be delivered
virtually! I’d still love to give a technical talk for your user group/conference at
some point.
To Cindy Velthuizen and Tom Ehren, for your support, advice, and time over the last
few years as I made this journey.
A huge thanks to Jonathan Gennick for reaching out, asking me if I would be
interested in writing a book, and helping me through those first stages.
To Shrikant Vishwakarma and Smriti Srivastava for your help while actually writing
the book and keeping me on track.
And everyone else at Apress who make getting books from Word documents on my
computer to being an actual book possible.
To my technical reviewers.
Marc Duiker for checking that I was doing the right things with the Azure Functions
through the chapters, and laughter at some of the comments I made.
And Jimmy Engström for doing the same with the Blazor code and helping me think
my way out of problems during the writing.
Of course, any issues that remain here are entirely down to me!
And to everyone else, too numerous to mention, who have helped me get this book
into readers’ hands.
xvii
Acknowledgments
Finally, my parents for always supporting me in what I wanted, and needed to do,
and cheering me on when it would have been so easy to give up at school, college, and
university. It means the world to me that you believed in me through those years.
And my partner and child, who wish to remain anonymous, but it wouldn’t be right
to not include them here. For your love, support, and helping me stay on track, I am
forever indebted.
xviii
CHAPTER 1
Introduction
A couple of years ago, I decided that I’d been putting off making my own website for too
long. With the technology available to us, it doesn’t need to be difficult or complex to
develop our own space on the Web. I didn’t want to run my site on a simple home page
application though, I wanted to experiment with new technologies and learn new things!
With this in mind, I have used Azure Static Web Apps, with Blazor and .NET Azure
functions, to develop my personal site over the last couple of years.
I’ve spoken at many conferences and meetups about the subject, and when I hear
that someone has taken what I’ve said and tried something by themselves, it gives me a
real buzz of excitement that I’ve helped someone take that step.
And so, I decided to write this book to take a beginner on their journey of discovery!
Before we get started though, a little background on the technology that we’ll
be using!
JamStack
A method of developing applications that is becoming ever more popular is JamStack.
That is, using markup files and JavaScript to make a dynamic application that runs in a
browser and then supplementing these with APIs to fetch and store data.
Splitting up our applications in this way allows us to take advantage of new ways
of hosting sites. Our application is made of static files, so we no longer need a complex
web server. We can simply host our files statically so that they can run inside of a user’s
browser.
As our back end now only serves data requests, rather than complete web pages,
we can use the growing number of serverless possibilities to host our API, allowing easy
deployment and scaling using technologies like Microsoft Azure Functions, Google
Cloud Functions, or AWS Lambda Functions.
3
© Stacy Cashmore 2022
S. Cashmore, Beginning Azure Static Web Apps, https://doi.org/10.1007/978-1-4842-8146-8_1
Chapter 1 Introduction
When we put this together, we get a hosting model that is simple and cheap – even
free – to put our application out into the world!
Over the last few years, this way of creating applications has been increasing in
popularity over traditional server-side generated applications that require dedicated web
servers to serve content.
BlamStack
JamStack is great for developers who use JavaScript technologies.
But there are lots of developers and development teams that use .NET with C#. Until
now, the JamStack way of developing applications was closed to these developers. Front-
end development in .NET was restricted to Web Forms or MVC. Both technologies have
their place – but both are also server technologies, with the final HTML being served to
the browser.
Then Blazor arrived! Originally released as a server technology, but with a browser
technology released soon after – Blazor WebAssembly – allowing us to take advantage of
using static files for our application.
Blazor WebAssembly runs on a .NET runtime compiled to run inside of a browser.
Not using any special plug-ins – this isn’t Silverlight for the 2020s – but using the built-in
WebAssembly runtime in the browsers themselves.
Blazor WebAssembly applications run the same way as JamStack applications. The
Blazor application handles the client application, running on the machine of the user
themselves, while an API provides the data to make the application dynamic. JamStack
but with Blazor: BlamStack!
Now we can take advantage of the paradigm using C# and .NET.
4
Chapter 1 Introduction
There are several ways to do this and with multiple providers. In 2021, Microsoft
introduced Azure Static Web Apps to make this possible in Azure.
Rather than deal with each of the components that make our application separately,
Azure Static Web Apps contain components all in one easy-to-manage resource.
The Azure Static Web App handles the global distribution of the static content and
even handles cache invalidation when a new version of the application is deployed.
They also have built-in Azure Functions to handle the API for our application.
Not only does this mean that we only need one Azure resource to handle storage,
distribution, and our Azure Functions, etc., but it also connects the static content to
those Azure Functions so that, to the outside world, it seems like it is one single resource.
This, again, simplifies our workflow by ensuring that we do not need to handle CORS
requests between the front end and back end.
And to make life even easier for us, we even get authentication out of the box with
several popular platforms, meaning that we can authenticate our users without ever
knowing their passwords!
If deploying from GitHub or Azure DevOps, we even get a simple continuous
integration and delivery (CI/CD) flow created at the same time as our application. The
fact that this works out of the box means that anyone can have a
high-quality CI/CD flow without having to invest time learning how to use those
pipelines, allowing for greater focus on the application itself!
It doesn’t mean that we are limited in our options though! As developers, we can take
more control over our Azure Static Web App if we need to, making it also suitable for the
enterprise environment.
Book Focus
On our journey through this book, we will be focusing on getting started with Azure
Static Web Apps, looking at what we can do to get an application into production, with
authentication.
At the end of our journey, I’ll leave you with some suggestions for you to carry on
your project after you have finished and allow yourself to learn even more.
The book is focused on a Windows development environment; it is possible to follow
along on any platform that supports .NET development – though some software will be
different to the descriptions in the books.
5
Chapter 1 Introduction
6
CHAPTER 2
Setting
Up the Environment
In this chapter, we will set up our development environment and required online
services so that we can create our first Azure Static Web App.
We will create the online accounts and repositories needed to host our Static Web
App and source code, clone the repo to our local machine, and install Visual Studio 2022
as an IDE to develop our applications locally. We can use any edition of Visual Studio for
the examples in this book, including the free Community Edition.
By the end of this chapter, we will have everything that we need, both online
accounts and resources on our local machine, to be ready to create and deploy our Azure
Static Web App.
If you already have all the required accounts and tools already installed and are
experienced in creating repositories in GitHub, then feel free to simply create a new
repository, clone it to your machine, and skip ahead to the next chapter!
7
© Stacy Cashmore 2022
S. Cashmore, Beginning Azure Static Web Apps, https://doi.org/10.1007/978-1-4842-8146-8_2
Chapter 2 Setting Up the Environment
8
Chapter 2 Setting Up the Environment
This will bring us to the Microsoft Azure free trial screen. Click the green “Get started
for free” button as seen in Figure 2-2.
A prompt will appear to log in to a Microsoft Account. If you do not already have an
account, you can create one instead.
In the course of this flow, you will need to enter a credit card as a payment method for
the subscription.
The flow to create the Azure Account asks for standard personal data (name, email,
phone, address, etc.).
When the portal is visible, the account is set up and ready.
GitHub Account
Next, we need to set up a GitHub account. This will be where our code repository lives
and will be used to deploy our Static Web Application into Azure.
1. Go to https://github.com.
3. In the page that opens up, enter the email and click “Continue.”
9
Chapter 2 Setting Up the Environment
Click “Continue.”
After completing the puzzle, GitHub will send an email with a code. This must be
entered on the form seen in Figure 2-4 to prove that we have access to the email address
we used.
10
Chapter 2 Setting Up the Environment
Now the email has been verified, we can continue to set up our account!
11. We can ignore the feature selection screen for the purpose of
this book.
Click “Continue.”
After selecting a plan, we will be redirected to our new GitHub dashboard as shown
in Figure 2-5.
11
Chapter 2 Setting Up the Environment
GitHub Repo
Now that we have a GitHub account, we will need to create a repository to hold our code
and from where we will be building and deploying our Azure Static Web App.
From the GitHub dashboard at the end of the last session, click “Create repository”
as shown in Figure 2-6.
This will open the screen where we enter the information needed to create a
repository.
12
Chapter 2 Setting Up the Environment
When creating a repository, it’s important to check that the owner of the repository is
set correctly. It should be correct by default, but it is always good to make sure!
Beyond this, there are a number of steps that we need to take to ensure that our
repository behaves as expected.
13
Chapter 2 Setting Up the Environment
README files are often used to convey the purpose of a repository, how to use
the application, how to set up and run the application for development, and any extra
information that could be useful.
Add a .gitignore
When creating software, many files get created which should only exist on the developer
machine where they are created. Visual Studio, for example, creates files to hold user
information, along with “bin” and “obj” files when code is built. These files do not need
version control. Also, there are files which may contain secrets, local settings files, for
instance, that we need to run code locally. These should never be pushed to a repository
for security reasons.
Depending on the development language, and environment, that is used, different
patterns of files should be ignored.
For this book, Visual Studio 2022 is going to be used, so we need a .gitignore tailored
to that environment.
Open the drop-down box as seen in Figure 2-7.
14
Chapter 2 Setting Up the Environment
As there are many options available, it is generally quicker and easier to filter the
options than to search through the whole list.
Type “Visual” into the filter box, and the list will be more specific as seen in
Figure 2-8.
15
Chapter 2 Setting Up the Environment
Select “VisualStudio.”
Choose a License
The last option is for the license used for the repository. This isn’t mandatory, but if we
are making a repository public, then consider adding a license to it. When we do this, it
will be displayed at the top of the repository when people visit the page.
This book does not cover what license models are best – that is a choice that the
repository owner needs to make. However, there are resources online that can help make
the selection. For further reading, follow the following links:
https://docs.github.com/en/repositories/managing-our-repositorys-
settings-and-features/customizing-our-repository/licensing-a-repository
https://choosealicense.com/
If a license is needed, select the required license from the list shown in Figure 2-9.
16
Chapter 2 Setting Up the Environment
As with the .gitignore, we can filter the list of options to find our preferred license.
Default Branch
When the README, .gitignore, or license option is checked, GitHub will initialize
the repository with a default branch in order to store those files. Extra information is
displayed on the page about the default branch as seen in Figure 2-10.
Now that all options are selected, the “Create New Repository” page should look
something like Figure 2-11.
17
Another Random Document on
Scribd Without Any Related Topics
Suomen, Ahvenanmaan ja monta paikkaa Ruotsissa läänitykseksi,
mutta täytyi heittää vallikan Kuninkaalle, joka kruunattiin vielä
samana vuonna 1497. Steeni Stuure sai kuitenki vielä olla yksi
neljästä Ruosia hallitsevasta Riiki-Raatista. Mutta pian vaikuttivat
vihamiehet, että hänen täytyi lahjoituksistansa antaa Turun, Hämeen
ja Savon linnat sekä läänit takasin Kuninkaalle.
Maunus III Stiernkorssista, joka nyt oli ollut pispana, ei löydy paljo
muuta mainittuna, kun että häntä kiitetään, että hänellä oli Kirkon
puolta pitäissänsä paljo vastuksia ja mielikarvaita, ja että hän oli
laittanut Dekaanin arvon Tuomiokirkolla, sekä muutenki pappivirkain
tuloja lisäillyt. Myös tietään hänen toimittaneen yhteisen
atrioitsemisen säätyveljillensä ja muillenki köyhille Turussa. Sammui
v. 1500.
Kolmas Aikakausi.