Skip to content

Commit

Permalink
feat(rest-crud): initial implementation
Browse files Browse the repository at this point in the history
Introduce a new package `@loopback/rest-crud` providing a controller
class implementing default CRUD operations for a given Entity.
  • Loading branch information
bajtos committed Aug 26, 2019
1 parent 04a2490 commit 4374160
Show file tree
Hide file tree
Showing 15 changed files with 800 additions and 1 deletion.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ packages/repository/* @raymondfeng
packages/repository-tests/* @bajtos
packages/repository-json-schema/* @bajtos
packages/rest/* @bajtos @raymondfeng
packages/rest-crud/* @bajtos @hacksparrow
packages/service-proxy/* @raymondfeng
packages/testlab/* @bajtos
packages/tsdocs/* @raymondfeng
Expand Down
1 change: 0 additions & 1 deletion docs/site/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ Please register the new package in the following files:

- Update [MONOREPO.md](./MONOREPO.md) - insert a new table row to describe the
new package, please keep the rows sorted by package name.
- Update
- Update [Reserved-binding-keys.md](./Reserved-binding-keys.md) - add a link to
the apidocs on Binding Keys if the new package has any.
- Update
Expand Down
1 change: 1 addition & 0 deletions docs/site/MONOREPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The [loopback-next](https://github.com/strongloop/loopback-next) repository uses
| [repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository) | @loopback/repository | Define and implement a common set of interfaces for interacting with databases |
| [repository-tests](https://github.com/strongloop/loopback-next/tree/master/packages/repository-tests) | @loopback/repository-tests | A shared test suite to verify `@loopback/repository` functionality with a given compatible connector |
| [rest](https://github.com/strongloop/loopback-next/tree/master/packages/rest) | @loopback/rest | Expose controllers as REST endpoints and route REST API requests to controller methods |
| [rest-crud](https://github.com/strongloop/loopback-next/tree/master/packages/rest-crud) | @loopback/rest-crud | REST API controller implementing default CRUD semantics |
| [service-proxy](https://github.com/strongloop/loopback-next/tree/master/packages/service-proxy) | @loopback/service-proxy | A common set of interfaces for interacting with service oriented backends such as REST APIs, SOAP Web Services, and gRPC microservices |
| [testlab](https://github.com/strongloop/loopback-next/tree/master/packages/testlab) | @loopback/testlab | A collection of test utilities we use to write LoopBack tests |
| [tsdocs](https://github.com/strongloop/loopback-next/tree/master/packages/tsdocs) | @loopback/tsdocs | An internal package to generate api docs using Microsoft api-extractor and api-documenter |
Expand Down
1 change: 1 addition & 0 deletions packages/rest-crud/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
25 changes: 25 additions & 0 deletions packages/rest-crud/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2019. All Rights Reserved.
Node module: @loopback/rest-crud
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
65 changes: 65 additions & 0 deletions packages/rest-crud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @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

```sh
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.

```ts
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.

```ts
class ProductController extends CrudRestController {
constructor(@repository(ProductRepository) repo: ProductRepository) {
super(repo);
}
}
```

5. Register the controller with your application.

```ts
app.controller(ProductController);
```

## Contributions

- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
6 changes: 6 additions & 0 deletions packages/rest-crud/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/crud-rest
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

export * from './dist';
6 changes: 6 additions & 0 deletions packages/rest-crud/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/crud-rest
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

module.exports = require('./dist');
8 changes: 8 additions & 0 deletions packages/rest-crud/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/crud-rest
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// DO NOT EDIT THIS FILE
// Add any additional (re)exports to src/index.ts instead.
export * from './src';
14 changes: 14 additions & 0 deletions packages/rest-crud/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions packages/rest-crud/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@loopback/rest-crud",
"version": "0.0.1",
"description": "REST API controller implementing default CRUD semantics",
"engines": {
"node": ">=8.9"
},
"main": "index",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "lb-tsc",
"clean": "lb-clean loopback-rest-crud*.tgz dist tsconfig.build.tsbuildinfo package",
"pretest": "npm run build",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"verify": "npm pack && tar xf loopback-rest-crud*.tgz && tree package && npm run clean"
},
"author": "IBM Corp.",
"copyright.owner": "IBM Corp.",
"license": "MIT",
"devDependencies": {
"@loopback/build": "^1.7.1",
"@loopback/repository": "^1.12.0",
"@loopback/rest": "^1.17.0",
"@loopback/testlab": "^1.7.4",
"@types/node": "^10.14.15"
},
"peerDependencies": {
"@loopback/repository": "^1.12.0",
"@loopback/rest": "^1.17.0"
},
"files": [
"README.md",
"index.js",
"index.d.ts",
"dist",
"src",
"!*/__tests__"
],
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback-next.git",
"directory": "packages/rest-crud"
}
}
Loading

0 comments on commit 4374160

Please sign in to comment.