Page Contents

Home > @loopback/rest-crud > defineCrudRestController

defineCrudRestController() function

Create (define) a CRUD Controller class for the given model.

Example usage:

const ProductController = defineCrudRestController<
Product,
typeof Product.prototype.id,
'id'
>(Product, {basePath: '/products'});

inject('repositories.ProductRepository')(
 ProductController,
  undefined,
  0,
);

app.controller(ProductController);

Signature:

export declare function defineCrudRestController<T extends Entity, IdType, IdName extends keyof T, Relations extends object = {}>(modelCtor: typeof Entity & {
    prototype: T & {
        [key in IdName]: IdType;
    };
}, options: CrudRestControllerOptions): CrudRestControllerCtor<T, IdType, IdName, Relations>;

Parameters

Parameter Type Description
modelCtor typeof Entity & {
prototype: T & {
[key in IdName]: IdType;
};
}
 
options CrudRestControllerOptions  

Returns:

CrudRestControllerCtor<T, IdType, IdName, Relations>