AdonisJS Tutorial - Middleware [ Build a Simple API - Part 7 ] (2018)

preview_player
Показать описание
In this video we'll briefly go over middleware and use it to dry up our code.

Middleware is a powerful way to hook into the app on certain routes and perform important tasks, ie: find a customer, validate some data, etc.

Рекомендации по теме
Комментарии
Автор

I'am using Adonis 4.1 and itsn not working for me. If you use same version try:


MIDDLEWARE: request.customer = customer
CONTROLLER: request.customer

SMBENTZ
Автор

Nice hint! What is difference between request.body.customer to request.post().customer on CustomerController > show()?

kauanmocelin
Автор

You could also make group for middleware rather then assigning same middleware multiple times:

// User Group Example
Route.group(() => {
Route.get('/users', 'User/UserController.index')
Route.get('/user', 'User/UserController.show')


On other hand great tutorials since there was lack of tutorials for Adonis. Also since i am frontend developer as well if you will need help for building better website using angular or nuxt rather then wordpress throw me an message :)

Take care and good luck!

nemanjadragun
Автор

Great Middleware video! .. Visual Studio Code has a cool debugger, you know if there is suck clean option for Sublime Text?

FranckMercado
Автор

In your example, how do I make sure that I do not forget to connect the middleware to a route? In your example the app would (hard?) crash if the middleware was not called (request.post().customer is undefined). But on the other hand when I am just looking at the controller (and not the routes) I have no clou that a middleware sets up things beforehand

MereddynYT
Автор

Could you apply this functionality to ajax calls?

jmartecep
Автор

Hey man thanks for the tutorial, you are a great teacher!
But btw, idk why I can't assign request.body.customer, it always return undefined, I have tried using request.post().customer too but still not working, my middleware is working though

pratamaa.sumirat
Автор

how about Middleware JWT / Personal API tokens ?
how to implement for all API endpoint

gitahanandika
Автор

Now instead of request.post() or request.get(), use request.body()

ducouteausect
welcome to shbcf.ru