UNPKG

@loopback/docs

Version:
60 lines (41 loc) 1.78 kB
--- lang: en title: 'API docs: rest-crud.definecrudrestcontroller' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar editurl: https://github.com/strongloop/loopback-next/tree/master/packages/rest-crud permalink: /doc/en/lb4/apidocs.rest-crud.definecrudrestcontroller.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/rest-crud](./rest-crud.md) &gt; [defineCrudRestController](./rest-crud.definecrudrestcontroller.md) ## defineCrudRestController() function Create (define) a CRUD Controller class for the given model. <b>Signature:</b> ```typescript 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 | <code>typeof Entity &amp; {</code><br/><code> prototype: T &amp; {</code><br/><code> [key in IdName]: IdType;</code><br/><code> };</code><br/><code>}</code> | A model class, e.g. <code>Product</code>. | | options | <code>CrudRestControllerOptions</code> | Configuration options, e.g. <code>{basePath: '/products'}</code>. | <b>Returns:</b> `CrudRestControllerCtor<T, IdType, IdName, Relations>` ## Example ```ts const ProductController = defineCrudRestController< Product, typeof Product.prototype.id, 'id' >(Product, {basePath: '/products'}); inject('repositories.ProductRepository')( ProductController, undefined, 0, ); app.controller(ProductController); ```