Questions & Answers

Can Deepkit handle complex parameter types in the routes?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

Yes, Deepkit can handle complex parameter types in the routes. You can use a parameter resolver to resolve complex parameter types. This allows you to decouple the HTTP abstraction from the route code and simplify testing and modularity. The resolver can be registered in the dependency injection container and used to provide the complex parameter type in the route function or method.

Here is an example of how to use a resolver to resolve a complex parameter type:

import { RouteParameterResolverContext, RouteParameterResolver } from '@deepkit/http';

class MyResolver implements RouteParameterResolver {
  async resolve(context: RouteParameterResolverContext) {
    // Resolve the complex parameter type here and return it
  }
}

@http.resolveParameter(ComplexParameterType, MyResolver)
class MyController {
  @http.GET('/myroute')
  myRoute(parameter: ComplexParameterType) {
    // Handle the complex parameter type here
  }
}

In this example, the MyResolver class implements the RouteParameterResolver interface to define how to resolve the complex parameter type. The @http.resolveParameter decorator is used to associate the resolver with the ComplexParameterType. This allows Deepkit to automatically resolve the complex parameter type in the myRoute method.