Page Contents
Home > @loopback/rest-crud > defineCrudRestController
defineCrudRestController() function
Create (define) a CRUD Controller class for the given model.
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; }; } | A model class, e.g. Product . |
options | CrudRestControllerOptions | Configuration options, e.g. {basePath: '/products'} . |
Returns:
CrudRestControllerCtor<T, IdType, IdName, Relations>
Example
const ProductController = defineCrudRestController<
Product,
typeof Product.prototype.id,
'id'
>(Product, {basePath: '/products'});
inject('repositories.ProductRepository')(
ProductController,
undefined,
0,
);
app.controller(ProductController);