JSPM

  • Created
  • Published
  • Downloads 1440
  • Score
    100M100P100Q111225F
  • License MIT

REST API controller implementing default CRUD semantics

Package Exports

  • @loopback/rest-crud

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@loopback/rest-crud) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@loopback/rest-crud

REST API controller implementing default CRUD semantics.

Overview

This module allows applications to quickly expose a model via REST API without having to implement a custom controller class.

Installation

npm install --save @loopback/rest-crud

Basic use

  1. Define your model class, e.g. using lb4 model tool.

  2. Create a Repository class, e.g. using lb4 repository tool.

  3. Create a base REST CRUD controller class for your model.

    const CrudRestController = defineCrudRestController<
      Product,
      typeof Product.prototype.id,
      'id'
    >(Product, {basePath: '/products'});
  4. Create a new subclass of the base controller class to configure repository injection.

    class ProductController extends CrudRestController {
      constructor(@repository(ProductRepository) repo: ProductRepository) {
        super(repo);
      }
    }
  5. Register the controller with your application.

    app.controller(ProductController);

Contributions

Tests

Run npm test from the root folder.

Contributors

See all contributors.

License

MIT