-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest-crud): initial implementation
Introduce a new package `@loopback/rest-crud` providing a controller class implementing default CRUD operations for a given Entity.
- Loading branch information
Showing
15 changed files
with
800 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.