-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: add example-hello-world #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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=false |
This file contains hidden or 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. 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. |
This file contains hidden or 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,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!`. | ||
|
|
This file contains hidden or 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. 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'; |
This file contains hidden or 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,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(); | ||
| } |
This file contains hidden or 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. 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'; |
This file contains hidden or 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,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" | ||
| ] | ||
| } |
This file contains hidden or 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,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 { | ||
| 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')}`); | ||
| } | ||
| } | ||
This file contains hidden or 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,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; | ||
| } |
This file contains hidden or 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 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/tsconfig", | ||
| "extends": "./node_modules/@loopback/build/config/tsconfig.common.json", | ||
| "compilerOptions": { | ||
| "rootDir": "." | ||
| }, | ||
| "include": ["index.ts", "src"] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
RestApplicationclass to avoid configuring the sequence handler insidestartmethod (which I consider as too late).