All language subtitles for 011 Refactoring Our Routes_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

Let's now refactor our code a little bit.

So basically, reorganize some of our route

to make the code a lot better.

So right now, we have all these routes here.

So the http method plus the url

together with the route handler,

which is this callback function.

Right?

And we have these routes and route handlers

kind of all over the place.

So we have this and then this and all after the other,

but it's kind of difficult to see

what route we actually have in our code.

So all the routes should kind of be together,

and then the handler functions also together.

So separate from these routes here.

Okay.

So what I'm gonna do is to go ahead

and basically export all of these handler functions

into their own function.

Okay?

First of all, let's also get rid of this

old code that we had here.

And so, yeah.

Take this.

Or actually, not just this.

So all of this.

Take this, and create a new function out of it.

So I'm calling this one getAllTours.

And then I'm assigning it this function.

Give it a save, and now here

instead of passing the callback function directly,

well, I just do getAllTours.

And that's it.

Okay?

And so right now, if I'm gonna hit this route here.

So this endpoint.

It will then simply call this getAllTours function.

So the functionality didn't change at all,

but I did slightly refactor my code.

Okay.

And you will see how nice this is gonna be

when all of the routes are together

and all these route handlers are also together.

So...

This one is getTour because this is only to get one tour.

Right?

Add to here, getTour.

So.

And we're starting to see different routes

that we have in our project at one glance.

So.

This is the next one, and it's gonna be createTour.

Const createTour equals all of this.

And here then createTour.

Next up we have...

Not like this.

We have updateTour.

All right.

And so this also actually makes our code

a little more clartive.

Right?

So we can see very easily what happens here

when we're actually reading the code.

So when we read this line of code,

we immediately see, oh, this will update to tour

because we actually have the function name here.

Okay.

And now finally, we have deleteTour.

Okay.

DeleteTour.

So.

This looks a lot nicer already,

but it's still not perfect.

We can do even better.

Because, let's say, that we want to, for example,

change the version or the resource name.

We would then have to change it

in all of these five places,

and that is not ideal.

And so instead of having all of this,

we can do something better.

So let me actually start it from scratch,

and write app dot route, so that's a new one.

And so here we specify the route that we want.

So let's start actually with this one here.

And then, on there is where we specify

what we want to happen on get.

Dot get.

Well, we want getAllTours.

So.

What we have here is right now

exactly the same as we have here.

Okay, so that's coming out this part.

So it's exactly the same.

Now, the thing is, that here we can now

actually chain the post method.

And then we can say createTour just like this.

Okay?

And so just like this,

we have now actually created an even better way

of writing a route because right now,

this is not repeated for the get and the post.

Okay.

Let's give it a save.

It's nicely formatted, and even easier to read than before.

Okay.

So.

The two route handlers that we use

on this kind of route here.

So without the id, is only for get and for post.

So for getting all tours, and for creating a new tour.

And now, as you can imagine,

let's do the same for the other route.

So basically at this url here.

So we add this url, and now,

we will have get, patch, and delete.

So this one is getTour.

This one is updateTour, ah it's already there.

And finally, I have deleteTour.

So deleteTour.

Give it a save.

And we can now go ahead and...

Well, I'm not gonna delete it.

So that we can keep the old code here as well.

But, this is gonna work just the exact same way,

but making the code a lot better,

and also easier to read.

Right?

So again, just to recap, we separated our handler function

of the route itself so that we can later actually,

even export these into another file.

Okay, so that will then make the code even better.

But for now, let's keep it at this.

So with the handlers nicely separated from the routes.

And then, we specified all the actions

for each of our two routes.

Which are simply tours

and then tours slash the id parameter.

So.

Just to make sure it still works,

let's use this one here.

And with a tour that actually is this.

But you can see already it's not giving us an error

and so it actually still works.

Same four getAllTours because that's another url.

And just to make sure it still works as well.

Indeed, it does.

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