Documentation:
https://docs.nestjs.com/
GitHub repository:
https://github.com/Ihorhavryliak/nest.
@youritdeveloper
Nest js / Перехоплювачі / Interceptors
Відео починається зі знайомства з перехоплювачами та їхньою роллю в конвеєрі програм. Перехоплювачі — це функції проміжного програмного забезпечення, які можна використовувати для перехоплення та модифікації вхідних і вихідних запитів HTTP до того, як вони будуть оброблені контролерами програми. Це дозволяє розробникам додавати додаткові функції до програми, такі як журналювання, обробка помилок і кешування.
Потім доповідач пояснює різні типи перехоплювачів, доступних у Nest JS, зокрема перехоплювачі запитів і відповідей. Перехоплювачі запитів використовуються для зміни вхідних запитів, тоді як перехоплювачі відповідей використовуються для зміни вихідних відповідей.
Основна увага відео зосереджена на практичному прикладі використання перехоплювачів у програмі Nest JS. Доповідач демонструє, як запровадити перехоплювачі, щоб додати функціональність журналювання до уявної програми онлайн-магазину. Перехоплювачі використовуються для реєстрації інформації про вхідні запити та вихідні відповіді, наприклад заголовки запитів, коди статусу відповіді та час відповіді.
Відео надає покрокові інструкції щодо впровадження перехоплювачів у програму, включаючи визначення перехоплювачів, їх налаштування в модулі програми та використання в контролерах програми. Доповідач також висвітлює деякі типові помилки розробників під час впровадження перехоплювачів і дає поради, як їх уникнути.
Загалом, цей підручник із перехоплювачів Nest JS є цінним ресурсом для розробників, які прагнуть покращити функціональність своїх програм Nest JS. Він містить чітке та стисле пояснення перехоплювачів і демонструє, як їх використовувати на практичному прикладі.
The video begins with an introduction to interceptors and their role in the application pipeline. Interceptors are middleware functions that can be used to intercept and modify incoming and outgoing HTTP requests before they are processed by the application's controllers. This allows developers to add additional functionality to the application, such as logging, error handling, and caching.
The presenter then goes on to explain the different types of interceptors available in Nest JS, including request and response interceptors. Request interceptors are used to modify incoming requests, while response interceptors are used to modify outgoing responses.
The main focus of the video is on a practical example of using interceptors in a Nest JS application. The presenter demonstrates how to implement interceptors to add logging functionality to an imaginary online store application. The interceptors are used to log information about incoming requests and outgoing responses, such as request headers, response status codes, and response times.
The video provides a step-by-step guide on how to implement interceptors in the application, including defining the interceptors, configuring them in the application module, and using them in the application's controllers. The presenter also highlights some of the common mistakes that developers make when implementing interceptors and provides tips on how to avoid them.
Overall, this Nest JS interceptors tutorial is a valuable resource for developers looking to enhance the functionality of their Nest JS applications. It provides a clear and concise explanation of interceptors and demonstrates how to use them in a practical example.