Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages/cli/* @raymondfeng @kjdelisle @shimks
packages/context/* @bajtos @raymondfeng @kjdelisle
packages/core/* @bajtos @raymondfeng @kjdelisle
packages/example-getting-started/* @bajtos @kjdelisle
packages/example-hello-world/* @b-admike
packages/example-log-extension/* @virkt25
packages/example-rpc-server/* @kjdelisle
packages/metadata/* @raymondfeng
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/generators/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const utils = require('../../lib/utils');
const EXAMPLES = {
'getting-started':
'An application and tutorial on how to build with LoopBack 4.',
'log-extension':
'An example extension project for LoopBack 4',
'hello-world': 'A simple hello-world Application using LoopBack 4',
'log-extension': 'An example extension project for LoopBack 4',
'rpc-server': 'A basic RPC server using a made-up protocol.',
};
Object.freeze(EXAMPLES);
Expand Down
1 change: 1 addition & 0 deletions packages/example-hello-world/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
25 changes: 25 additions & 0 deletions packages/example-hello-world/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2018. All Rights Reserved.
Node module: @loopback/example-hello-world
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.
49 changes: 49 additions & 0 deletions packages/example-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @loopback/example-hello-world

A simple hello-world application using LoopBack 4!

## Summary

This project shows how to write the simplest LoopBack 4 application possible.
Check out [src/application.ts](src/application.ts) to learn how we configured
our application to always respond with "Hello World!".

## Prerequisites

Before we can begin, you'll need to make sure you have some things installed:
- [Node.js](https://nodejs.org/en/) at v6.x or greater

Additionally, this tutorial assumes that you are comfortable with
certain technologies, languages and concepts.
- JavaScript (ES6)
- [npm](https://www.npmjs.com/)
- [REST](https://en.wikipedia.org/wiki/Representational_state_transfer)

## Installation

1. Install the new loopback CLI toolkit.
```
npm i -g @loopback/cli
```

2. Download the "hello-world" application.
```
lb4 example hello-world
```

3. Switch to the directory and install dependencies.
```
cd loopback-example-hello-world && npm i
```

## Use

Start the app:

```
npm start
```

The application will start on port `3000`. Use your favourite browser or REST
client to access any path with a GET request, and watch it return `Hello world!`.

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

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

const nodeMajorVersion = +process.versions.node.split('.')[0];
const dist = nodeMajorVersion >= 7 ? './dist' : './dist6';

const application = (module.exports = require(dist));

if (require.main === module) {
// Run the application
application.main();
}
8 changes: 8 additions & 0 deletions packages/example-hello-world/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/example-hello-world
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// DO NOT EDIT THIS FILE
// Add any aditional (re)exports to src/index.ts instead.
export * from './src';
41 changes: 41 additions & 0 deletions packages/example-hello-world/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@loopback/example-hello-world",
"version": "4.0.0-alpha.0",
"description": "A simple hello-world Application using LoopBack 4",
"private": true,
"main": "index.js",
"engines": {
"node": ">=6"
},
"scripts": {
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
"build:dist6": "lb-tsc es2015",
"build:apidocs": "lb-apidocs",
"clean": "lb-clean *example-hello-world*.tgz dist dist6 package api-docs",
"prepublishOnly": "npm run build && npm run build:apidocs",
"verify": "npm pack && tar xf *example-hello-world*.tgz && tree package && npm run clean",
"start": "npm run build && node ."
},
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback-next.git"
},
"license": "MIT",
"dependencies": {
"@loopback/core": "^4.0.0-alpha.29",
"@loopback/rest": "^4.0.0-alpha.21"
},
"devDependencies": {
"@loopback/build": "^4.0.0-alpha.10",
"@types/node": "^8.5.9"
},
"keywords": [
"loopback",
"LoopBack",
"example",
"tutorial"
]
}
28 changes: 28 additions & 0 deletions packages/example-hello-world/src/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/example-hello-world
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Application} from '@loopback/core';
import {RestApplication, RestServer} from '@loopback/rest';

export class HelloWorldApplication extends RestApplication {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from https://github.com/strongloop/loopback4-example-hello-world, I am leveraging the new RestApplication class to avoid configuring the sequence handler inside start method (which I consider as too late).

constructor() {
super();

// In this example project, we configure a sequence that always
// returns the same HTTP response: Hello World!
// Learn more about the concept of Sequence in our docs:
// http://loopback.io/doc/en/lb4/Sequence.html
this.handler((sequence, request, response) => {
sequence.send(response, 'Hello World!');
});
}

async start() {
await super.start();

const rest = await this.getServer(RestServer);
console.log(`REST server running on port: ${await rest.get('rest.port')}`);
}
}
16 changes: 16 additions & 0 deletions packages/example-hello-world/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/example-hello-world
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {HelloWorldApplication} from './application';

export async function main() {
const app = new HelloWorldApplication();
try {
await app.start();
} catch (err) {
console.error(`Unable to start application: ${err}`);
}
return app;
}
8 changes: 8 additions & 0 deletions packages/example-hello-world/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "./node_modules/@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["index.ts", "src"]
}