---
lang: en
title: 'API docs: rest-crud.definecrudrestcontroller'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/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.

**Signature:**

```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

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td markdown="1">

modelCtor


</td><td markdown="1">

typeof Entity &amp; { prototype: T &amp; { \[key in IdName\]: IdType; }; }


</td><td markdown="1">

A model class, e.g. `Product`<!-- -->.


</td></tr>
<tr><td markdown="1">

options


</td><td markdown="1">

[CrudRestControllerOptions](./rest-crud.crudrestcontrolleroptions.md)


</td><td markdown="1">

Configuration options, e.g. `{basePath: '/products'}`<!-- -->.


</td></tr>
</tbody></table>

**Returns:**

[CrudRestControllerCtor](./rest-crud.crudrestcontrollerctor.md)<!-- -->&lt;T, IdType, IdName, Relations&gt;

## Example


```ts
const ProductController = defineCrudRestController<
Product,
typeof Product.prototype.id,
'id'
>(Product, {basePath: '/products'});

inject('repositories.ProductRepository')(
 ProductController,
  undefined,
  0,
);

app.controller(ProductController);
```


