Search Header Logo

NestJS - Request Lifecycle

Authored by Leonardo Davinci

Information Technology (IT)

Professional Development

Used 1+ times

NestJS - Request Lifecycle
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

32 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which order best represents the NestJS HTTP request lifecycle for a successful request?

Pipes → Guards → Middleware → Controller → Interceptors

Middleware → Pipes → Guards → Controller → Interceptors

Middleware → Guards → Interceptors (before) → Pipes → Controller/Handler → Interceptors (after) → Response

Guards → Middleware → Pipes → Controller → Interceptors

Answer explanation

Nest first runs middleware, then guards (authorization), then interceptors (pre), then pipes (validation/transformation), then the handler, then interceptors (post), finally writing the response.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You need to reject unauthenticated requests before expensive DTO validation and body parsing. Where do you put the logic?

Pipe

Guard

Interceptor

Exception filter

Answer explanation

Guards run before pipes and short-circuit requests early, ideal for auth/authz checks.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What does this controller do in the lifecycle?

Validates and transforms dto after the handler returns

Validates and transforms dto before entering the handler

Only transforms dto, never validates

Skips global pipes

Answer explanation

Pipes (method-scoped here) run before the handler, validating and (optionally) transforming inputs.

4.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

You want to log latency and also map the handler result into a consistent { data, meta } envelope. Which components fit best?

Single interceptor that times the call and maps the response

Pipe that times the call and maps the response

Two interceptors composed: one for timing, one for mapping

Guard for timing, interceptor for mapping

Exception filter for timing

Answer explanation

Interceptors can measure pre/post handler execution and shape responses. Pipes validate/transform inputs, not outputs.

5.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

About exception filters:

They catch exceptions thrown anywhere including middleware

A method-scoped filter only applies to that route handler

Global filters can be overridden by controller-scoped filters

Filters can format framework/unknown errors into HTTP responses

Filters run before guards

Answer explanation

Filters catch exceptions after the handler (and inside the Nest context). Classic Express middleware errors aren’t caught unless integrated. Scope matters; more specific scopes take precedence for that route.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

Where is userId resolved in the lifecycle?

ParseIntPipe runs after the handler

ParseIntPipe runs before the handler; header extraction is simple mapping

ParseIntPipe and header extraction are both interceptors

Both happen in guards

Answer explanation

Pipes validate/transform route params before the handler. Basic header extraction is parameter resolution; no pipe here.

7.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

You need to attach the authenticated user to the request so it’s visible to services via a request-scoped provider. Best approaches:

In a guard, validate and set request.user = payload

In an interceptor, mutate request.user after the handler

Use @Inject(REQUEST) in a REQUEST-scoped provider to read user

Use a pipe to inject user into DTO

Create a global filter to set request.user on success

Answer explanation

Guards populate request context before handler; REQUEST-scoped providers can inject the REQUEST to access it. Pipes shape inputs, not ambient context.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?