GithubHelp home page GithubHelp logo

tut_nestjs_interceptors's Introduction

Nest.js | Middleware, Pipes & Interceptors Explained By Example

Follow along notes from Michael Guay on Youtube
Source: https://www.youtube.com/watch?v=x1W3FJ1RJlM
All credits to Michael Guay for the lesson.

What I learned is that the path a request goes through in order is...

  1. Middleware - For things like authenticating a user
  2. Guards - To check a user is authenticated before getting to the controller (manager of the task) among other use cases
  3. Interceptor (before) - Can be used to log the method, url, userAgent, ip, controller name (ie., AppController), controller handler/method name (ie., getHello). Can also be used to transform incoming data
  4. Pipes - Can be used to freeze parameters in the request so it isn't mistakenly changed in the code. Also validate input data, transform input data, etc. Typical usage is validating request parameters with built in NestJS pipes like ParseIntPipe, ParseArrayPipe, ParseUUIDPipe
  5. Route handler - The "manager" that tells the provider (ie., service/worker/task implementer) what to do
  6. Interceptor (after) - Can get the response and status code after handled by the control handler (ie., the method/function inside the manager). Useful for logging. Can be accessed via next.handle().pipe(tap(res=>{}))
  7. Exception filters - To log errors internally or change the error response into user friendly wording for better UI Then it becomes a beautiful response

Diagram by Demisx: nestjs pipeline Source

tut_nestjs_interceptors's People

Contributors

williamwongx avatar paulwongx avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.