All language subtitles for 012 Middleware and the Request-Response Cycle_Downloadly.ir_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

In the ;ast couple of lectures,

I hope you started getting the fundamentals

of Express development.

And so now is the perfect time to dive a bit deeper

into how Express works,

and for that we need to talk about middleware

and the request-response cycle.

So really the essence of Express development

is to understand

and then use request-response cycle.

So I wanna make that idea really clear

in a visual way in this video.

So to start the request-response cycle,

or Express app receives a request when someone hits a server

for which it will then create a request

and response object.

That data will then be used and processed

in order to generate and send back a meaningful response.

Now, in order to process that data,

in Express we use something called middleware,

which can manipulate the request or the response object.

Or really execute any other code that we like.

So middleware doesn't always have to be just

about the request or the response object,

but it usually is mostly about the request.

And actually, we already used middleware before.

We used Express dot JSON to get access to the request body

on the request object.

Remember that?

Now it's called middleware remember

because it's a function that is executed between,

so in the middle of receiving the request

and sending the response.

And actually, we can say that in Express,

everything is middleware.

Even our route definitions.

So again, even when we defined our routes,

we can think of the route handler functions that we wrote

as middleware functions.

They are simply middleware functions

that are only executed for certain routes.

Okay?

Now some examples of middleware are Express dot JSON,

which is also called body-parser,

and that we already used before.

Or some logging functionality,

or setting some specific http headers.

The possibilities are really endless with middleware.

All right, and now in more technical terms,

we say that all the middleware together

that we use in our app,

is called the middleware Stack.

What's very important to keep in mind here,

is that the order of middleware in the stack,

is actually defined by the order they

are defined in the code.

So a middleware that appears first in the code,

is executed before one that appears later.

And so the order of the code matters a lot in Express.

Okay?

Now, you can think of the whole process like this,

our request and response object

that were created in the beginning

go through each middleware where they are processed,

or where just some other code is executed.

Then at the end of each middleware function,

a next function is called,

which is a function that we have access to

in each middleware function.

Just like the request and response objects.

And we will of course see this in code in the next video.

So when we call the next function,

the next middleware in the stack will be executed

with the exact same request and response object.

And that happens with all the middlewares

until we reach the last one.

And so just like this,

the initial request and response object

go through each middleware step by step.

And you can think of this whole process

as kind of a pipeline where our data go through,

so just like its been piped from request to final response.

All right?

Now about that last middleware function,

it's usually a route handler just like we coded before.

So in this handler we do actually not call the next function

to move to the next middleware.

Instead, we finally send the response data

back to the client.

And like this,

we then finish the so-called request-response cycle.

So the request-response cycle is really everything

that we talked about here together.

It starts with the incoming request,

then executing all the middleware in the middleware stack

step by step,

and finally sending the response to finish the cycle.

So you see, it's really not complicated.

It's actually just a linear process.

But I wish someone would have shown me something like this

when I was learning how to build Express apps.

I mean I could build them,

but in the beginning I didn't really understand

this entire request-response cycle like this.

It was very confusing.

So that's why I'm showing you this,

because I believe it will be much, much, easier for you

in order to move onto the course now,

after understanding exactly how Express apps work.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.