Skip to content

Commit e13bcc7

Browse files
committed
feat(example-greeting-app): add a new example to demonstrate loopback core
1 parent b28d8b6 commit e13bcc7

29 files changed

+1031
-0
lines changed

examples/greeting-app/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=true

examples/greeting-app/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
*.json

examples/greeting-app/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"bracketSpacing": false,
3+
"singleQuote": true,
4+
"printWidth": 80,
5+
"trailingComma": "all"
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"editor.rulers": [80],
3+
"editor.tabCompletion": "on",
4+
"editor.tabSize": 2,
5+
"editor.trimAutoWhitespace": true,
6+
"editor.formatOnSave": true,
7+
8+
"files.exclude": {
9+
"**/.DS_Store": true,
10+
"**/.git": true,
11+
"**/.hg": true,
12+
"**/.svn": true,
13+
"**/CVS": true,
14+
"dist": true,
15+
},
16+
"files.insertFinalNewline": true,
17+
"files.trimTrailingWhitespace": true,
18+
19+
"tslint.ignoreDefinitionFiles": true,
20+
"typescript.tsdk": "./node_modules/typescript/lib"
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Watch and Compile Project",
8+
"type": "shell",
9+
"command": "npm",
10+
"args": ["--silent", "run", "build:watch"],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
},
15+
"problemMatcher": "$tsc-watch"
16+
},
17+
{
18+
"label": "Build, Test and Lint",
19+
"type": "shell",
20+
"command": "npm",
21+
"args": ["--silent", "run", "test:dev"],
22+
"group": {
23+
"kind": "test",
24+
"isDefault": true
25+
},
26+
"problemMatcher": ["$tsc", "$tslint5"]
27+
}
28+
]
29+
}

examples/greeting-app/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) IBM Corp. 2019. All Rights Reserved.
2+
Node module: @loopback/example-greeting-app
3+
This project is licensed under the MIT License, full text below.
4+
5+
--------
6+
7+
MIT license
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.

examples/greeting-app/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# @loopback/example-greeting-app
2+
3+
This application is built on top of
4+
[`@loopback/example-greeter-extension`](https://github.com/strongloop/loopback-next/tree/master/examples/greeter-extension).
5+
6+
## Compose the application
7+
8+
1. Add REST API
9+
10+
- GreetingController - providing endpoints over `GreetingService`
11+
12+
2. Add caching
13+
14+
- CachingService - implementing cache operations, such as set,get, delete,
15+
and sweep
16+
- CachingInterceptor - intercepting http requests to apply caching
17+
- CacheObserver - watching and sweeping cache in the background
18+
19+
![greeting-app](./greeting-app.png)
20+
21+
## Contributions
22+
23+
- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
24+
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)
25+
26+
## Try out
27+
28+
Run `npm start`:
29+
30+
The service is running at http://127.0.0.1:3000/greet/world.
31+
32+
Open your browser to try the REST APIs. You can replace `world` with other
33+
names.
34+
35+
The following `curl` command sets `Accept-Language` header to `zh` to receive
36+
the greeting in Chinese.
37+
38+
```sh
39+
curl -H 'Accept-Language: zh' http://127.0.0.1:3000/greet/Ray
40+
```
41+
42+
```json
43+
{
44+
"timestamp": "2019-05-29T22:48:03.040Z",
45+
"language": "zh",
46+
"greeting": "Ray,你好!"
47+
}
48+
```
49+
50+
## Tests
51+
52+
Run `npm test` from the root folder.
53+
54+
## Contributors
55+
56+
See
57+
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).
58+
59+
## License
60+
61+
MIT
353 KB
Loading

examples/greeting-app/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/example-greeting-app
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
export * from './dist';

examples/greeting-app/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/example-greeting-app
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
module.exports = require('./dist');
7+
8+
async function main() {
9+
const config = {
10+
rest: {
11+
port: +(process.env.PORT || 3000),
12+
host: process.env.HOST || '127.0.0.1',
13+
openApiSpec: {
14+
// useful when used with OASGraph to locate your application
15+
setServersFromRequest: true,
16+
},
17+
},
18+
};
19+
const app = new module.exports.GreetingApplication(config);
20+
await app.main();
21+
const url = app.restServer.url;
22+
console.log(`The service is running at ${url}/greet/world.`);
23+
}
24+
25+
if (require.main === module) {
26+
main().catch(err => {
27+
console.error('Cannot start the application.', err);
28+
process.exit(1);
29+
});
30+
}

0 commit comments

Comments
 (0)