blindBind function

RouteHandler blindBind (
  1. String argName,
  2. Type argType
)

Implementation

RouteHandler blindBind(String argName, Type argType) {
  return (Context ctx) async {
    if (_isBuiltIn(argType)) {
      // Try "path parameter"
      if (ctx.pathParams.containsKey(argName)) {
        return PathParam(argName).inject(argName, argType, ctx);
      }
      // Try "query"
      if (ctx.query.containsKey(argName)) {
        return QueryParam(argName).inject(argName, argType, ctx);
      }
    }
    // Try variable
    {
      final ret = ctx.getVariable(type: argType);
      if (ret != null) return ret;
    }
    // Try JSON deserializer
    if (ctx.isJson) {
      if (argType == Map) return ctx.bodyAsJsonMap();
      if (argType != List) {
        // Try JSON PODO deserialization
        final ser = ctx.serializerFor(argType);
        if (ser != null) return ser.fromMap(await ctx.bodyAsJsonMap());
      }
    }
    return null;
  };
}