Get Web API Development for the Absolute Beginner A Step by step Approach to Learning the Fundamentals of Web API Development with NET 7 1st Edition Irina Dominte PDF ebook with Full Chapters Now
Get Web API Development for the Absolute Beginner A Step by step Approach to Learning the Fundamentals of Web API Development with NET 7 1st Edition Irina Dominte PDF ebook with Full Chapters Now
com
OR CLICK BUTTON
DOWLOAD EBOOK
https://ebookname.com/product/asp-net-web-api-2-2nd-edition-jamie-
kurtz/
ebookname.com
https://ebookname.com/product/asp-net-web-api-2-recipes-a-problem-
solution-approach-1st-edition-filip-wojcieszyn-auth/
ebookname.com
https://ebookname.com/product/practical-asp-net-web-api-1st-edition-
badrinarayanan-lakshmiraghavan-auth/
ebookname.com
https://ebookname.com/product/restless-giant-the-united-states-from-
watergate-to-bush-vs-gore-1st-edition-edition-james-t-patterson/
ebookname.com
An introduction to invariants and moduli 1st Edition
Shigeru Mukai
https://ebookname.com/product/an-introduction-to-invariants-and-
moduli-1st-edition-shigeru-mukai/
ebookname.com
https://ebookname.com/product/consciousness-theatre-literature-and-
the-arts-2013-1st-edition-daniel-meyer-dinkgrafe/
ebookname.com
https://ebookname.com/product/science-of-memory-concepts-1st-edition-
henry-l-roediger-iii/
ebookname.com
https://ebookname.com/product/maternal-child-nursing-4th-edition-
emily-slone-mckinney-msn-rn-c/
ebookname.com
https://ebookname.com/product/applied-ei-the-importance-of-attitudes-
in-developing-emotional-intelligence-1st-edition-tim-sparrow/
ebookname.com
The First Modern Jew Spinoza and the History of an Image
Daniel B. Schwartz
https://ebookname.com/product/the-first-modern-jew-spinoza-and-the-
history-of-an-image-daniel-b-schwartz/
ebookname.com
Web API
Development for
the Absolute
Beginner
A Step-by-step Approach to
Learning the Fundamentals of
Web API Development with .NET 7
—
Irina Dominte
Web API Development for the Absolute Beginner: A Step-by-step Approach
to Learning the Fundamentals of Web API Development with .NET 7
Irina Dominte
Iasi, Romania
Acknowledgments�����������������������������������������������������������������������������xix
Introduction���������������������������������������������������������������������������������������xxi
v
Table of Contents
vi
Table of Contents
Status Codes�������������������������������������������������������������������������������������������������������43
1xx – Informational����������������������������������������������������������������������������������������43
2xx – Success�����������������������������������������������������������������������������������������������43
3xx – Redirects����������������������������������������������������������������������������������������������44
4xx – Client Errors�����������������������������������������������������������������������������������������44
5xx – Server Errors����������������������������������������������������������������������������������������46
Cookies���������������������������������������������������������������������������������������������������������������47
Summary������������������������������������������������������������������������������������������������������������49
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
x
Table of Contents
Chapter 8: Routing����������������������������������������������������������������������������235
What Is a Route?�����������������������������������������������������������������������������������������������235
Route Templates������������������������������������������������������������������������������������������236
Route Segments������������������������������������������������������������������������������������������237
Route Parameters����������������������������������������������������������������������������������������239
Route Tokens�����������������������������������������������������������������������������������������������240
Route Values������������������������������������������������������������������������������������������������241
Convention-based Routing��������������������������������������������������������������������������������241
Attribute Routing�����������������������������������������������������������������������������������������������242
Route Template Precedence�����������������������������������������������������������������������������246
How to Customize Routing��������������������������������������������������������������������������������247
Route Constraints����������������������������������������������������������������������������������������������248
Creating a Custom Route Constraint�����������������������������������������������������������249
Available Constraints�����������������������������������������������������������������������������������252
Creating Hierarchical Routes����������������������������������������������������������������������������253
Summary����������������������������������������������������������������������������������������������������������260
Chapter 9: Middleware���������������������������������������������������������������������261
Middleware Usage Scenarios���������������������������������������������������������������������������264
Introducing Custom Middleware�����������������������������������������������������������������������265
Create Your Own Middleware to Add Headers��������������������������������������������������267
Making an Extension Method for Our Middleware��������������������������������������������268
Understanding the Security Headers We Added�����������������������������������������������271
X-Content-Type-Options������������������������������������������������������������������������������271
X-Frame-Options�����������������������������������������������������������������������������������������271
X-Permitted-Cross-Domain-Policies�����������������������������������������������������������272
X-XSS-Protection�����������������������������������������������������������������������������������������273
Summary����������������������������������������������������������������������������������������������������������274
xi
Table of Contents
xii
Table of Contents
xiii
Table of Contents
Index�������������������������������������������������������������������������������������������������403
xiv
About the Author
Irina Dominte(Scurtu) is an independent
consultant and trainer, international
speaker, software architect, Microsoft MVP
for developer technologies, and Microsoft
certified trainer (MCT) with a wealth of
experience. Having taught classes, workshops,
and presentations for over 2,000 hours, Irina is
passionate about coding and keeping abreast
of the latest trends and best practices in
software architecture and .NET.
Twice a year, for five months each time, Irina teaches .NET and
C# to aspiring software developers or people interested in software
development or seeking to expand their knowledge. She is an active
member of the community and has founded the DotNet Iasi User Group
and the dotnetdays.ro conference, where she connects with like-minded
developers who are eager to share their expertise and insights.
Irina is also a prolific blogger, and her website, https://irina.codes,
features a wealth of articles on various coding topics. She decided to write
this book after learning firsthand how much people struggle to grasp new
concepts without proper guidance.
xv
About the Technical Reviewer
Layla Porter is an experienced software
engineer and developer advocate specializing
in .NET technologies. She’s a Microsoft MVP,
GitHub Star, and Progress Ninja, and in 2021
she founded the #WomenOfDotNet Initiative.
Layla has spoken at developer conferences
all over Europe and North America and is a
YouTube content creator and streamer. She
spends her time hiking, reading urban fantasy,
playing video games with her husband, and
doting on her two miniature pinschers, Cookie
and Lily.
xvii
Acknowledgments
The completion of this book wouldn’t have been possible without the help
and support of many people.
First, I want to thank my husband, who supported me every step and
encouraged me. Second, my daughter, Ilinca, who luckily enjoyed going
to daycare so I could write this book, and my in-laws, who were there to
babysit when I needed them.
Furthermore, I would like to express my appreciation to all those who
took the time to review my manuscript and provide constructive feedback
that helped refine the content. Special recognition goes to my tech
reviewer, Layla Porter, and my friends, Maria Rusu, Andrei Diaconu, and
Alexandra Nechita.
Last, but not least, thanks to my former students Tatiana Ciurescu and
Cosmin Dumitru, who were brave enough to shift their careers into tech
and never stopped learning.
xix
Introduction
This book aims to provide you, the reader, with a step-by-step approach
to learning Web API development. We start by introducing basic concepts
related to the Web in general and end with more advanced topics like
testing an API.
Across the chapters, you will notice a lot of things that might be subject
to debate—like splitting the code into different libraries, using different
coding standards, or even writing code that requires more lines than I
would use in real life.
Everything I choose to use in this book in terms of coding conventions,
API architecture, libraries, and topics covered was tested and proved
successful over the last eight years. In my spare time, twice a month,
I teach .NET to people that come from totally different domains than
programming. The vast majority now work in IT, and I dare to think that I
made a small contribution to that by using this approach.
xxi
PART I
The Basics
CHAPTER 1
What Is an API?
The term API is very widely used in the information technology (IT)
industry, and sometimes its usage can be confusing. The term is an
acronym for “application programmable interface.”
This is in fact the interface that gives a person or a system the ability to
interact with a piece of hardware or software through the operations that
are exposed.
Think about an API as a remote control, controlling your TV. You
press buttons to change the channels back and forth. Something similar
happens with APIs. You call methods and endpoints, or set values to
properties that are exposed to control aspects of that system.
While regular web applications are intended for humans to interact
with, APIs are like web applications but don’t have buttons or cute layouts
to interact with. Their intent is to be consumed by different “users.” In this
case, the “user” of an API might be a system or a developer.
There are many types of APIs with different scopes and addressability,
and they can be found in different parts of the web, or offline on devices.
Categorizing APIs
Now, if we ask ourselves, “What other kinds of APIs exist?” we may not
have a simple answer. Categorizing an API is a difficult job because we
need to add context to it. Imagine we have a set of LEGO blocks we need
to categorize. We might split them by color, or maybe by size. The same
happens with APIs—we can find more than one way to categorize them. In
the next section, we will talk about a few types of APIs that I have found to
be the most common and important.
Types of APIs
Push/Stream APIs
Push/stream APIs are event driven and send real-time notifications to
clients. In most cases, a web server will “push” messages or notifications
to a web browser. The business domain where you find APIs of this
category involves messaging, chats, video, streaming, or payments. There
is a significant chance of finding such APIs where time and real-time
processing are paramount.
Underneath, these APIs sometimes use protocols like WebSockets or
technologies like SignalR.
4
Chapter 1 Introducing Web API
Native APIs
APIs that are native usually are the interface of a device or a tool, allowing
us to interact with the device or tool. For example, web browsers have
a JavaScript API embedded that allows them to interpret and execute
the JavaScript code used in web applications. The same JavaScript API
will allow us to write and execute code directly in the Console tab of
developer tools.
In a similar manner, we can access our smartphone’s camera or
accelerometer through the exposed native API.
SDKs
An SDK, or software development kit, is a package of tools written in
different languages that helps developers build applications on top of that
package. For example, the .NET SDK provides a set of libraries and tools
that can be used by developers to build their own APIs or web applications.
SDKs get delivered as installers or as part of an Integrated Development
Environment workload and sometimes give you scaffolding capabilities
through those IDEs.
REST
REST, or representational state transfer, is an architectural style in the API
world that comes with a set of principles and guidelines about how to
design your API and leverage the underlying protocol in the correct way.
5
Chapter 1 Introducing Web API
REST was first mentioned by Roy Fielding in his dissertation thesis in 20001.
Since then, it has gained a lot of traction in the IT industry, but some
concepts were misunderstood.
Most of the APIs you will encounter in the web world are written in this
way. Not all respect the REST guidelines as they should, and are in fact JSON
over HTTP, but this is another subject that we will tackle at the right moment.
We will talk more about REST in a dedicated chapter.
RPC APIs
RPC is a term that means “remote procedure call,” and it has been
around for a while now in various forms. This model will look like you
are calling methods from the same application and using classes from
within the same scope or solution, but in fact the methods are hosted on a
different machine over the network. One of its main purposes is to make a
distributed system look and behave like a monolith.
If we look at Listing 1-1, the method calls seem to be part of the same
system, due to how an RPC API looks like. The calls to CreateOrder() and
ProcessPaymentFor() are actually calls over the network boundaries, even
if the look and feel for developers are local.
1
https://resources.sei.cmu.edu/asset_files/WhitePaper/2017_019_001_
505040.pdf
6
Chapter 1 Introducing Web API
7
Chapter 1 Introducing Web API
In the example that follows, you can see an HTML Tag Helper that
when executed generates an HTML input tag:
@Html.TextBoxFor(x=>x.AddedDate)
We can say that these application models are like self-contained boxes,
as shown in Figure 1-1.
The ASP Razor Pages application model comes with a nice structure, as
shown in Figure 1-2, and is very easy to understand and work with.
8
Chapter 1 Introducing Web API
Listing 1-2 and Listing 1-3 explore how a page would look in this
application model. We should have such source code file pairs for each
page we add to our application.
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about
<a href="https://docs.microsoft.com/aspnet/core">building Web
apps with ASP.NET Core</a>.</p>
</div>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApplication1.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
9
Chapter 1 Introducing Web API
}
10
Discovering Diverse Content Through
Random Scribd Documents
Fig. 261.—Valves of a Chiton
separated to show the
various parts (anterior valve
uppermost): a, a,
articulamentum; b, beak; j,
jugum; pl, pl, pleura; t, t,
tegmentum.
Fig. 262.—Valves of Chitonellus
separated out (anterior valve
uppermost): a, a,
articulamentum; t, t,
tegmentum. × 2.
The Polyplacophora are characterised, externally, by their usually
articulated shell of eight plates or valves, which is surrounded and
partly kept in position by a muscular girdle. These plates overlap like
tiles on a roof in such a way that the posterior edge of the first,
cephalic, or anterior valve projects over the anterior edge of the
succeeding valve, which in its turn overlaps the next, and so on
throughout. Seven-valved monstrosities very rarely occur.
A certain portion of each valve is covered either by the girdle or by
the valve next anterior to it. This portion, which is whitish in colour
and non-porous in structure, forms part of an inner layer which
underlies the rest of the substance of the valve, and is called the
articulamentum. The external portion of the valves, or tegmentum, is
generally more or less sculptured, and is largely composed of chitin,
impregnated with salts of lime, thus answering more to a cuticle than
to a shell proper. It is very porous, being pierced by a quantity of
minute holes of two sizes, known as megalopores and micropores,
which are connected together by minute canals containing what is
probably fibrous or nerve tissue, the mouths of the pores being
occupied by sense organs connected with these nerves. The
tegmentum of the six intermediate valves is generally divided into
three triangular areas by two more or less prominent ribs, which
diverge from the neighbourhood of the median beak or umbo. The
space enclosed between these ribs is known as the median area or
jugum, the other two spaces as the lateral areas or pleura. The ribs
terminate with the edge of the tegmentum, and are not found on the
articulamentum. In certain genera these areas are either non-
existent, or are not distinctly marked. The sculpture of the lateral
areas (which is, as a rule, much stronger than that of the median
area) will generally be found to resemble that of the anterior valve,
which has no proper median area. In the posterior valve the median
area is very small, while the sculpture of the rest of the valve
corresponds to that of the lateral areas generally (see Fig. 261).
Fig. 263.—First, fourth, and eighth
valves of a Chiton, showing l.i,
laminae of insertion; n, n,
notches; s.l, s.l, sutural
laminae. × 2.
The articulamentum of the intermediate valves is divided into two
equal parts in the middle of the anterior edge, opposite to the beak,
by a sinus. Each of the portions thus formed is again divided by a
notch or suture into two unequal parts, the anterior of which is known
as the sutural lamina, and is more or less concealed by the valve in
front of it, while the lateral part, or lamina of insertion, is entirely
concealed by the girdle. The articulamenta of the anterior and
posterior valves are either simple or pierced by a series of notches
(Fig. 263).
The girdle of the Chitonidae varies considerably in character.
Sometimes its upper surface is simply corneous or cartilaginoid, with
no other sculpture than fine striae, at others it is densely beset with
spines or bristles, or tufted at intervals with bunches of deciduous
hairs; again it is marbled like shagreen or mossy down, or covered
with serpent-like scales. The width of the girdle varies greatly, being
sometimes very narrow, sometimes entirely covering all the valves
(Cryptochiton). As a rule, its outer edge is continuous, but in
Schizochiton it is sharply notched over the anus.
A description has already been given of the dorsal eyes in Chiton
(p. 187), the nervous system (p. 202), the branchiae (p. 154), the
radula (p. 228), and the generative system (p. 126).
Fig. 267.—Chaetoderma
nitidulum Lov.: a, anus; m,
mouth. × 3.
Fam. 2. Chaetodermatidae.—Body cylindrical, no ventral groove,
liver a single sac, kidneys with separate orifices into the branchial
cloaca, two bipectinate ctenidia. Single genus, Chaetoderma (Fig.
267).
Fig. 269.—Pleurotomaria
adansoniana Cr. and F., Tobago.
× ½.
Fam. 4. Bellerophontidae.—Shell nautiloid, spire generally
concealed, aperture large, sinus or perforations central (Fig. 179, p.
266). Ordovician—Trias. Genera: Bellerophon, Trematonotus,
Cyrtolites.
Section II. Azygobranchiata.—One ctenidium (the left) present.
Fam. 1. Cocculinidae.—A single cervical ctenidium, foot broad, no
eyes, shell patelliform, with caducous spire. Single genus, Cocculina.
Deep water.
Fam. 2. Stomatellidae.—A single (left) ctenidium, front third free,
shell nacreous, spiral or patelliform, depressed, last whorl large.
Jurassic——. Genera: Stomatella (subg. Synaptocochlea, Niphonia),
shell depressed, spirally ribbed, spire short, operculum present;
Phaneta, fluviatile only, shell trochiform, imperforate, last whorl
keeled, sinuate in front; Stomatia, spire short, surface tubercled or
keeled, no operculum; Gena, shell haliotis-shaped, surface smooth,
aperture very large; Broderipia, shell patelliform, spiral apex often
lost.
Fam. 3. Cyclostrematidae.—Tentacles ciliated, thread-like, snout
bilobed, foot truncated in front, angles produced into a filament, shell
depressed, umbilicated, not nacreous. Eocene——. Principal
genera: Cyclostrema, Teinostoma, Vitrinella.
Fam. 4. Liotiidae.—Epipodial line with a lobe behind each eye-
peduncle, shell solid, trochiform, longitudinally ribbed or trellised,
aperture round, operculum multispiral, hispid, corneous, with a
calcareous layer. Silurian——. Principal genera: Liotia,
Craspedostoma (Silurian), Crossostoma (Jurassic).
Fig. 273.—Solarium
perspectivum Lam., Eastern
Seas.
Fam. 10. Littorinidae.—Proboscis short, broad, tentacles long,
eyes at their outer bases, penis behind the right tentacle;
reproduction oviparous or ovoviviparous, radula very long; shell
turbinate, solid, columella thickened, lip simple, operculum corneous,
nucleus excentrical. Jurassic——. Principal genera: Littorina (radula,
Fig. 16, p. 20), Cremnoconchus (p. 16), Fossarina; Tectarius, shell
tubercled or spinose; Risella, base slightly concave; Lacuna, shell
thin, grooved behind the columellar lip.
Fam. 11. Fossaridae.—Shell turbinate, solid, small, white, spirally
ribbed, outer lip simple. Miocene——. Principal genus, Fossarus.
Fam. 12. Cyclophoridae.—Ctenidium replaced by a pulmonary
sac, tentacles long, thread-like (radula, Fig. 17, p. 21); shell variously
spiral, peristome round, often reflected, operculum circular.
Terrestrial only. Cretaceous——. (i.) Pomatiasinae, shell high,
conical, longitudinally striated, operculum consisting of two laminae
united together. Single genus, Pomatias. (ii.) Diplommatininae, shell
more or less pupiform, peristome thickened or reflected, often
double. Genera: Diplommatina (subg., Nicida, Palaina, Paxillus,
Arinia), shell dextral or sinistral, small, columella often denticulated;
Opisthostoma (Fig. 208, p. 309), last whorl disconnected, often
reflected back upon the spire. (iii.) Pupininae, shell more or less
lustrous, bluntly conical, lip with a channel above or below. Genera:
Pupina (subg., Registoma, Callia, Streptaulus, Pupinella, Anaulus),
Hybocystis (Fig. 205, p. 305), Cataulus, Coptochilus,
Megalomastoma. (iv.) Cyclophorinae, shell turbinate or depressed,
operculum corneous or calcareous. Genera: Alycaeus,
Craspedopoma, Leptopoma, Lagochilus, Cyclophorus (Fig. 206, p.
306); including Diadema, Aulopoma, Ditropis, and others),
Aperostoma (including Cyrtotoma and others), Cyathopoma,
Pterocyclus (subg., Myxostoma, Spiraculum, Opisthoporus, and
Rhiostoma (Fig. 180, p. 266), Cyclotus, Cyclosurus, and
Strophostoma.
Fam. 13. Cyclostomatidae.—Ctenidium replaced by a pulmonary
sac, tentacles obtuse, foot with a deep longitudinal median groove;
central tooth, lateral, and first marginal more or less bluntly cusped,
second marginal large, edge pectinate; shell variously spiral, spire
usually elevated, aperture not quite circular; operculum generally
with an external calcareous and an internal cartilaginoid lamina,
rarely corneous. Terrestrial only. Cretaceous——. Genera:
Cyclostoma (subg., Leonia, Tropidophora, Rochebrunia, Georgia,
Otopoma, Lithidion, Revoilia), Cyclotopsis, Choanopoma (subg.,
Licina, Jamaicia, Ctenopoma, Diplopoma, Adamsiella), Cistula
(subg., Chondropoma, Tudora), Omphalotropis (subg., Realia,
Cyclomorpha), Hainesia, Acroptychia.
Fig. 274.—Cyclostoma
campanulatum Pfr., Madagascar.
Fam. 14. Aciculidae.—Ctenidium replaced by a pulmonary sac,
tentacles cylindrical, pointed at the end, eyes behind their base, foot
long and narrow; central tooth and lateral very similar, pinched in at
the sides, external marginal broad, edge finely pectinate; shell small,
acuminate, with a blunt spire, operculum corneous. Terrestrial only.
Tertiary——. Genus, Acicula (= Acme).
Fam. 15. Truncatellidae.—Ctenidium replaced by a pulmonary
sac, proboscis very long, eyes sessile, behind the base of the
tentacles, shell small, evenly cylindrical, apex truncated in the adult.
Eocene——. Genera: Truncatella (subg., Taheitia, Blanfordia, and
Tomichia), Geomelania (subg., Chittya and Blandiella), Cecina (?).
Fam. 16. Rissoidae.—Eyes at the external base of the tentacles,
epipodium with filaments, operculigerous lobe with appendages;
central tooth pleated at the basal angles, lateral large, bluntly
multicuspid, marginals long, narrow, denticulate at the edge; shell
small, acuminate, often elaborately sculptured, mouth entire or with a
shallow canal, operculum corneous. Marine or brackish water.
Jurassic——. Principal genera: Rissoa (subg., Folinia, Onoba,
Alvania, Cingula, Nodulus, Anabathron, Fenella, Iravadia, and
others), Scaliola (shell agglutinating fragments of sand, etc.),
Rissoina (lip thickened, operculum with an apophysis as in Nerita),
Barleeia, Paryphostoma (Eocene).
Fam. 17. Hydrobiidae.—Eyes at the outer base of the tentacles,
penis behind the right tentacle, prominent, operculigerous lobe
without filaments; radula rissoidan, central tooth often with basal
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com