### Start the Binding Resolution Example Application Source: https://github.com/loopbackio/loopback-next/blob/master/examples/binding-resolution/README.md Use this command to start the example application. Set the DEBUG environment variable to "loopback:example:binding-resolution" to see detailed logs. ```sh DEBUG=loopback:example:binding-resolution npm start ``` -------------------------------- ### Install LoopBack Example Source: https://github.com/loopbackio/loopback-next/blob/master/examples/passport-login/README.md Installs the passport login example locally using the lb4 CLI. ```sh lb4 example passport-login ``` -------------------------------- ### Start the Example Application Source: https://github.com/loopbackio/loopback-next/blob/master/examples/access-control-migration/README.md Run the example application using npm start. The server will be available at http://127.0.0.1:3000. Further testing instructions are available in the 'try it out' section of the documentation. ```sh $ npm start Server is running at http://127.0.0.1:3000 ``` -------------------------------- ### Clone and Start LoopBack 4 Example API Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Preparing-the-API-for-consumption.shelved.md Use these commands to clone the example todo application, install dependencies, and start the server. Access the API explorer at http://localhost:3000/explorer. ```sh lb4 example todo cd loopback4-example-todo npm start ``` -------------------------------- ### Install Dependencies and Start Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Create-your-first-app copy.md Navigate to the project directory, install npm packages, and start the LoopBack 4 application. The application includes a /ping endpoint for testing. ```sh cd getting-started npm install npm start ``` -------------------------------- ### Install and Start LoopBack Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Creating-servers.md Standard npm commands to install project dependencies and start the LoopBack application server. ```bash npm i && npm start ``` -------------------------------- ### Start Application Command Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/express-with-lb4-rest-tutorial.md Command to start the application after setup. ```sh npm start ``` -------------------------------- ### Navigate and Install Dependencies Source: https://github.com/loopbackio/loopback-next/blob/master/examples/passport-login/README.md Changes into the example directory and installs required npm dependencies. ```sh cd loopback4-example-passport-login && npm i ``` -------------------------------- ### Project Setup Prompts Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Create-your-first-app copy.md Example inputs for scaffolding a new LoopBack 4 project. These define the project's name, description, root directory, and application class. ```sh ? Project name: getting-started ? Project description: Getting started tutorial ? Project root directory: getting-started ? Application class name: StarterApplication ? Select features to enable in the project: ❯◉ Enable eslint: add a linter with pre-configured lint rules ◉ Enable prettier: install prettier to format code conforming to rules ◉ Enable mocha: install mocha to run tests ◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-eslint) ◉ Enable editorconfig: add EditorConfig files ◉ Enable vscode: add VSCode config files ◉ Enable docker: include Dockerfile and .dockerignore ◉ Enable repositories: include repository imports and RepositoryMixin ◉ Enable services: include service-proxy imports and ServiceMixin ``` -------------------------------- ### Download LoopBack 4 Example using CLI Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Examples.md Use the `lb4 example` command to download a specific example project. Ensure you have the LoopBack 4 CLI installed. ```sh lb4 example ``` ```sh lb4 example hello-world ``` -------------------------------- ### Install and Use Authentication Component Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Component.md This example shows how to install the `@loopback/authentication` package and then register the `AuthenticationComponent` with a LoopBack application instance. ```sh npm install --save @loopback/authentication ``` ```typescript import {RestApplication} from '@loopback/rest'; import {AuthenticationComponent} from '@loopback/authentication'; const app = new RestApplication(); // Add component to Application, which provides bindings used to resolve // authenticated requests in a Sequence. app.component(AuthenticationComponent); ``` -------------------------------- ### Download LoopBack 4 Example Project Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Tutorials.md Use this command to download a tutorial project. Ensure you have the LoopBack 4 CLI installed. ```sh lb4 example ``` -------------------------------- ### Basic Application Setup with GraphQLComponent Source: https://github.com/loopbackio/loopback-next/blob/master/extensions/graphql/README.md Configure the GraphQLComponent in your LoopBack application. This example shows how to set it up as middleware. ```ts export class MyApplication extends BootMixin(RestApplication) { constructor(config: ApplicationConfig) { super(config); this.projectRoot = __dirname; this.component(GraphQLComponent); this.configure(GraphQLBindings.GRAPHQL_SERVER).to({asMiddlewareOnly: true}); } } ``` -------------------------------- ### Navigate and Run LoopBack 4 Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/tutorials/soap-calculator/soap-calculator-tutorial-scaffolding.md After scaffolding, change into the project directory and run the application using 'npm start'. Dependencies are automatically installed. ```sh cd soap-calculator npm start ``` -------------------------------- ### Run Individual Examples Source: https://github.com/loopbackio/loopback-next/blob/master/examples/context/README.md Build the project and then run individual examples using this command. Replace with the specific example file name. ```sh npm run build node dist/ ``` -------------------------------- ### Install @loopback/model-api-builder Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Extending-Model-API-builder.md Install the necessary package to start building custom model APIs. ```sh npm install --save @loopback/model-api-builder ``` -------------------------------- ### Start LoopBack Application Source: https://github.com/loopbackio/loopback-next/blob/master/examples/todo/README.md Navigate to the cloned directory and start the application using npm start. The server will be running at http://127.0.0.1:3000. ```sh cd loopback4-example-todo npm start ``` -------------------------------- ### Create a LoopBack Application with REST and gRPC Servers Source: https://github.com/loopbackio/loopback-next/blob/master/packages/core/README.md Initialize a LoopBack application and mount REST and gRPC components. This example demonstrates how to configure ports for both servers and start them, retrieving server instances for logging. ```typescript // index.ts import { Application, RestServer, GrpcServer, } from '@loopback/core'; import {RestComponent} from '@loopback/rest'; import {GrpcComponent} from '@loopback/grpc'; const app = new Application({ rest: { port: 3000, }, grpc: { port: 3001, }, }); app.component(RestComponent); // REST Server app.component(GrpcComponent)( // GRPC Server async function start() { // Let's retrieve the bound instances of our servers. const rest = await app.getServer('RestServer'); const grpc = await app.getServer('GrpcServer'); // Define all sorts of bindings here to pass configuration or data // between your server instances, define controllers and datasources for them, // etc... await app.start(); // This automatically spins up all your servers, too! console.log(`REST server running on port: ${rest.getSync('rest.port')}`); console.log(`GRPC server running on port: ${grpc.getSync('grpc.port')}`); }, )(); ``` -------------------------------- ### Basic "Hello World" LoopBack REST Application Source: https://github.com/loopbackio/loopback-next/blob/master/packages/rest/README.md A basic "Hello World" application using @loopback/rest. This example demonstrates setting up a simple REST application and starting the server. ```typescript import {RestApplication, RestServer} from '@loopback/rest'; const app = new RestApplication(); app.handler(({request, response}, sequence) => { sequence.send(response, 'hello world'); }); (async function start() { await app.start(); const server = await app.getServer(RestServer); const port = await server.get('rest.port'); console.log(`Server is running at http://127.0.0.1:${port}`); })(); ``` -------------------------------- ### Start Benchmark Source: https://github.com/loopbackio/loopback-next/blob/master/benchmark/README.md Run this command to start the benchmark process. ```bash $ npm start ``` -------------------------------- ### Install @loopback/boot Source: https://github.com/loopbackio/loopback-next/blob/master/packages/boot/README.md Install the @loopback/boot package using npm. ```shell $ npm i @loopback/boot ``` -------------------------------- ### Install Dependencies Source: https://github.com/loopbackio/loopback-next/blob/master/benchmark/README.md Run this command to install all necessary dependencies for the project. ```bash $ npm install ``` -------------------------------- ### Start LoopBack Application Source: https://github.com/loopbackio/loopback-next/blob/master/examples/lb3-application/README.md This is the main function to start the LoopBack Express server. It boots the application and then starts the server, logging the server URL. ```typescript export {ApplicationConfig, ExpressServer}; export async function main(options: ApplicationConfig = {}) { const server = new ExpressServer(options); await server.boot(); await server.start(); console.log(`Server is running at ${server.url}`); } ``` -------------------------------- ### Install @loopback/http-caching-proxy Source: https://github.com/loopbackio/loopback-next/blob/master/packages/http-caching-proxy/README.md Install the package as a development dependency. ```sh npm install --save-dev @loopback/http-caching-proxy ``` -------------------------------- ### Install @loopback/http-server Source: https://github.com/loopbackio/loopback-next/blob/master/packages/http-server/README.md Install the @loopback/http-server package using npm. ```sh npm i @loopback/http-server ``` -------------------------------- ### Install @loopback/repository Source: https://github.com/loopbackio/loopback-next/blob/master/packages/repository/README.md Install the repository package using npm. ```sh npm install --save @loopback/repository ``` -------------------------------- ### Install @loopback/core Source: https://github.com/loopbackio/loopback-next/blob/master/packages/core/README.md Install the @loopback/core package using npm. ```shell npm install --save @loopback/core ``` -------------------------------- ### Install @loopback/graphql Source: https://github.com/loopbackio/loopback-next/blob/master/extensions/graphql/README.md Install the package using npm. ```sh npm install --save @loopback/graphql ``` -------------------------------- ### Install @loopback/authorization Source: https://github.com/loopbackio/loopback-next/blob/master/packages/authorization/README.md Install the authorization component using npm. ```shell npm install --save @loopback/authorization ``` -------------------------------- ### Install @loopback/rest-explorer Source: https://github.com/loopbackio/loopback-next/blob/master/packages/rest-explorer/README.md Install the REST API Explorer component using npm. ```sh npm install --save @loopback/rest-explorer ``` -------------------------------- ### Create a new LoopBack 4 app Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/deployment/Deploying-with-pm2-and-nginx.md Use the LoopBack CLI to generate a new application. Refer to the getting started guide for detailed instructions. ```sh $ lb4 app ``` -------------------------------- ### Install @loopback/cli Source: https://github.com/loopbackio/loopback-next/blob/master/packages/cli/README.md Run this command to install the LoopBack 4 CLI globally. ```bash $ npm install -g @loopback/cli ``` -------------------------------- ### Install @loopback/context Source: https://github.com/loopbackio/loopback-next/blob/master/packages/context/README.md Install the @loopback/context package using npm. ```sh npm install --save @loopback/context ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/express-with-lb4-rest-tutorial.md Change the current directory to the cloned example project. ```sh cd loopback4-example-express-composition ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/loopbackio/loopback-next/blob/master/examples/soap-calculator/README.md Change the current directory to the cloned example project. ```sh cd loopback4-example-soap-calculator ``` -------------------------------- ### Install @loopback/pooling Source: https://github.com/loopbackio/loopback-next/blob/master/extensions/pooling/README.md Install the @loopback/pooling package using npm. ```sh npm install --save @loopback/pooling ``` -------------------------------- ### Download Hello World Example Source: https://github.com/loopbackio/loopback-next/blob/master/examples/hello-world/README.md Downloads the 'hello-world' LoopBack 4 application template. Navigate into the downloaded directory to proceed. ```sh lb4 example hello-world ``` -------------------------------- ### Install @loopback/sequelize Source: https://github.com/loopbackio/loopback-next/blob/master/extensions/sequelize/README.md Install the core extension package using npm. ```sh npm install @loopback/sequelize ``` -------------------------------- ### Download Example Project Source: https://github.com/loopbackio/loopback-next/blob/master/packages/context/README.md Use the LoopBack CLI to download a standalone example project for @loopback/context. ```sh lb4 example context ``` -------------------------------- ### Clone Express Composition Example Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/express-with-lb4-rest-tutorial.md Clone the express-composition repository to get a pre-built example application. ```sh lb4 example express-composition ``` -------------------------------- ### Install passport-http and types Source: https://github.com/loopbackio/loopback-next/blob/master/extensions/authentication-passport/README.md Install the passport-http strategy and its type definitions for use with the adapter. This is required for the examples provided. ```sh npm i passport-http @types/passport-http --save ``` -------------------------------- ### Example: Exclude Specific Debuggers Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Setting-debug-strings.md Prefix debuggers with '-' to exclude them. This example includes all debuggers except those starting with 'rest-crud:'. ```shell DEBUG=*,-rest-crud:* ``` -------------------------------- ### Application Boot and Start Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Inside-Loopback-Application.md Entry point for booting and starting the LoopBack application. Calls app.boot() and app.start() to initialize and run the server. ```typescript import {ShoppingApplication} from './application'; export async function main(args: string[] = []) { const app = new ShoppingApplication({basePath: '/api'}); await app.boot(); await app.start(); const url = app.restServer.url; console.log(`🚀 Application is running on ${url}`); return app; } ``` -------------------------------- ### Prepare Documentation Preview Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/DEVELOPING.md Run this command once to set up the preview environment for LoopBack documentation. It creates a Jekyll project in `docs/_preview` and configures symlinks. ```sh $ npm run docs:prepare ``` -------------------------------- ### ESLint Warning Example (Avoid) Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Developing-with-vscode.md An example of an ESLint warning message that should be avoided, indicating that a rule requires type information. This is used to verify ESLint setup. ```text Warning: The 'no-unused-variable' rule requires type information. ``` -------------------------------- ### Example Product Data for API Design Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Defining-the-API-using-design-first-approach.shelved.md Define example data as JavaScript objects to guide the initial API specification. This helps in identifying resources and their properties. ```javascript const products = [ { name: 'Headphones', price: 29.99, category: '/categories/accessories', available: true, deals: ['50% off', 'free shipping'], }, { name: 'Mouse', price: 32.99, category: '/categories/accessories', available: true, deals: ['30% off', 'free shipping'], }, { name: 'yPhone', price: 299.99, category: '/categories/phones', available: true, deals: ['free shipping'], }, { name: 'yBook', price: 5999.99, category: '/categories/computers', available: true, }, ]; ``` -------------------------------- ### Start Documentation Preview Server Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/DEVELOPING.md Use this command to render and serve the documentation locally. Subsequent runs are faster due to Jekyll's incremental mode. ```sh $ npm run docs:start ``` -------------------------------- ### Example of LB4 CLI Autocompletion Prompt Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Command-line-interface.md After installing completion, typing `lb4` and pressing tab twice will show available commands. This example demonstrates the prompt for commands. ```sh $ lb4 app example observer service controller extension openapi update copyright import-lb3-models relation datasource interceptor repository discover model rest-crud ``` -------------------------------- ### Implement a Life Cycle Observer Source: https://github.com/loopbackio/loopback-next/blob/master/skills/loopback-core/references/interceptors-and-observers.md Implement the LifeCycleObserver interface to participate in application start and stop events. This example shows a caching observer that starts and stops a CachingService. ```typescript import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; import {CachingService} from '../caching-service'; import {CACHING_SERVICE} from '../keys'; @lifeCycleObserver('caching') export class CacheObserver implements LifeCycleObserver { constructor( @inject(CACHING_SERVICE) private cachingService: CachingService, ) {} async start(): Promise { await this.cachingService.start(); } async stop(): Promise { await this.cachingService.stop(); } } ``` -------------------------------- ### Download RPC Server Example Source: https://github.com/loopbackio/loopback-next/blob/master/examples/rpc-server/README.md Download the 'rpc-server' example application using the LoopBack CLI. ```sh lb4 example rpc-server ``` -------------------------------- ### Example JSON Response for Get Todos Query Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Using-openapi-to-graphql.md This is an example of the JSON output you can expect when querying for all to-do instances. It shows a list of to-do objects, each with an ID, title, and description. ```json { "data": { "todos": [ { "id": 1, "title": "Take over the galaxy", "desc": "MWAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA" }, { "id": 2, "title": "destroy alderaan", "desc": "Make sure there are no survivors left!" }, { "id": 3, "title": "play space invaders", "desc": "Become the very best!" }, {"id": 4, "title": "crush rebel scum", "desc": "Every.Last.One."} ] } } ``` -------------------------------- ### Observer with Method Injection Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Life-cycle.md Example of a `LifeCycleObserver` implementing `init`, `start`, and `stop` methods that accept injected arguments. ```typescript class MyObserverWithMethodInjection implements LifeCycleObserver { status = 'not-initialized'; init(@inject('prefix') prefix: string) { this.status = `${prefix}:initialized`; } start(@inject('prefix') prefix: string) { this.status = `${prefix}:started`; } stop(@inject('prefix') prefix: string) { this.status = `${prefix}:stopped`; } } ``` -------------------------------- ### Boot and Start Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/express-with-lb4-rest-tutorial.md Add methods to boot the LoopBack application and start the Express server. Includes logic for handling server listening and graceful shutdown. ```typescript import {once} from 'events'; export class ExpressServer { public readonly app: express.Application; public readonly lbApp: NoteApplication; private server?: http.Server; constructor(options: ApplicationConfig = {}) { //... } async boot() { await this.lbApp.boot(); } public async start() { await this.lbApp.start(); const port = this.lbApp.restServer.config.port ?? 3000; const host = this.lbApp.restServer.config.host || '127.0.0.1'; this.server = this.app.listen(port, host); await once(this.server, 'listening'); } // For testing purposes public async stop() { if (!this.server) return; await this.lbApp.stop(); this.server.close(); await once(this.server, 'close'); this.server = undefined; } } ``` -------------------------------- ### Sample Application Output Source: https://github.com/loopbackio/loopback-next/blob/master/examples/greeter-extension/README.md This output is generated by running `npm start` from the root folder of the sample application, demonstrating the configured greetings. ```text English: Hello, Raymond! Chinese: Raymond,你好! ``` -------------------------------- ### Configure Component in Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Creating-components.md This example shows how to configure a component within an application's setup. It uses `this.configure()` to set options for a component and then registers the component with `this.component()`. ```typescript ... // MyComponent.COMPONENT is the binding key of MyComponent this.configure(MyComponent.COMPONENT).to({ enableLogging: true, }); this.component(MyComponent); ... ``` -------------------------------- ### Install Shell Autocompletion for LB4 CLI Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Command-line-interface.md Enable shell autocompletion for the `lb4` command by running `lb4 install-completion`. This command guides you through selecting your shell and configuring the necessary files. ```sh lb4 install-completion ``` -------------------------------- ### Force Transient Binding Scope in Example Source: https://github.com/loopbackio/loopback-next/blob/master/examples/binding-resolution/README.md To override default binding scopes and force all bindings to be transient, set the BINDING_SCOPE environment variable to "transient" when starting the application. ```sh DEBUG=loopback:example:binding-resolution BINDING_SCOPE=transient npm start ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/loopbackio/loopback-next/blob/master/examples/hello-world/README.md Changes the current directory to the downloaded LoopBack 4 'hello-world' application. ```sh cd loopback4-example-hello-world ``` -------------------------------- ### Perform Key-Value Operations with Repository Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Repository.md Instantiate the repository and perform basic key-value operations like set, get, and delete. Note that this example assumes the existence of givenShoppingCart1 and givenShoppingCart2 functions. ```typescript // Please note the ShoppingCartRepository can be instantiated using Dependency // Injection const repo: ShoppingCartRepository = new ShoppingCartRepository(new RedisDataSource()); const cart1: ShoppingCart = givenShoppingCart1(); const cart2: ShoppingCart = givenShoppingCart2(); async function testKV() { // Store carts using userId as the key await repo.set(cart1.userId, cart1); await repo.set(cart2.userId, cart2); // Retrieve a cart by its key const result = await repo.get(cart1.userId); console.log(result); }); testKV(); ``` -------------------------------- ### Start the Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/express-with-lb4-rest-tutorial.md Start the LoopBack application. The server will be running at http://127.0.0.1:3000. ```sh $ npm start Server is running at http://127.0.0.1:3000 ``` -------------------------------- ### Create a LoopBack Todo Example Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Using-openapi-to-graphql.md Use this command to create a new LoopBack 4 application based on the 'todo' example. This serves as a prerequisite for the tutorial. ```sh lb4 example todo ``` -------------------------------- ### Define a LoopBack Component with Asynchronous Bindings Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Component.md This example demonstrates how a LoopBack component can contribute bindings asynchronously using the `init` method. It also includes `start` and `stop` methods for lifecycle management. ```typescript export class MyComponent implements Component, LifeCycleObserver { // ... async init() { // Contribute bindings via `init` const val = await readFromConfig(); this.app.bind('abc').to(val); this.status = 'initialized'; this.initialized = true; } async start() { this.status = 'started'; } async stop() { this.status = 'stopped'; } } ``` -------------------------------- ### Query Suppliers with Accounts via HTTP Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/HasOne-relation.md This is an example of how to query suppliers and include their related accounts using an HTTP GET request. The filter parameter with 'include' is used to specify the related model. ```http GET http://localhost:3000/suppliers?filter[include][]=account ``` -------------------------------- ### Build and Prepare Full Website Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/DEVELOPING.md This command clones the `loopback.io` repository and copies current LoopBack documentation into the Jekyll project for a full website build. ```sh npm run build:site ``` -------------------------------- ### Enable Debug Mode in LoopBack Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Troubleshooting.md To get more detailed error information, start your application with a specific debug string using the `DEBUG` environment variable. Refer to the 'Setting debug strings' documentation for a full list of available debug strings. ```bash DEBUG= npm start ``` -------------------------------- ### Generate Soap Calculator Example Source: https://github.com/loopbackio/loopback-next/blob/master/examples/soap-calculator/README.md Generate and clone the soap-calculator example repository using the LoopBack 4 CLI. ```sh lb4 example soap-calculator ``` -------------------------------- ### Setup Dockerized CouchDB for Testing Source: https://github.com/loopbackio/loopback-next/blob/master/acceptance/repository-cloudant/README.md Execute the setup script to configure a Dockerized CouchDB instance for testing. Optional parameters can be provided for host, port, user, password, and database. ```bash . setup.sh ``` -------------------------------- ### Generate LoopBack Controller with CRUD Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/tutorials/connectors/Mysql-tutorial.md Use the `lb4 controller` CLI command to generate a new controller. This example scaffolds a REST controller with basic CRUD functions for a 'User' model, including repository setup and API path configuration. ```bash $ lb4 controller ? Controller class name: user Controller User will be created in src/controllers/user.controller.ts ? What kind of controller would you like to generate? REST Controller with CRUD functions ? What is the name of the model to use with this CRUD repository? User ? What is the name of your CRUD repository? UserRepository ? What is the name of ID property? id ? What is the type of your ID? number ? Is the id omitted when creating a new instance? Yes ? What is the base HTTP path name of the CRUD operations? /users ``` -------------------------------- ### Controller Methods Using Array and Object Schemas with x-ts-type Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/decorators/Decorators_openapi.md Provides controller methods that utilize the previously defined OpenAPI schemas for arrays and objects containing `x-ts-type` models. These examples cover POST requests for object properties and deep arrays, and a GET request for an array of models. ```typescript export class SomeController { @post('/my-controller') greetObjectProperty( @requestBody({ content: {'application/json': {schema: schemaWithObjectPropOfMyModel}}, }) body: { myModel: MyModel; }, ): string { return `hello ${body.myModel.name}!`; } @get('/my-controllers', { responses: { '200': { description: 'hello world', content: {'application/json': {schema: schemaWithArrayOfMyModel}}, }, }, }) everyone(): MyModel[] { return [{name: 'blue'}, {name: 'red'}]; } @post('/my-controllers') greetEveryone( @requestBody({ content: {'application/json': {schema: schemaDeepArrayOfMyModel}}, }) body: MyModel[][], ): string { return `hello ${body.map(objs => objs.map(m => m.name))}`; } } ``` -------------------------------- ### Setup Dockerized PostgreSQL Instance Source: https://github.com/loopbackio/loopback-next/blob/master/acceptance/repository-postgresql/README.md Use this script to set up a PostgreSQL instance using Docker. Optional parameters can be provided for host, port, user, password, and database. ```bash source setup.sh ``` -------------------------------- ### Define Controller Method with Route and Query Parameter Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Controller.md This example shows a basic LoopBack controller method that handles GET requests to '/messages'. It uses decorators to define the route and a query parameter, and interacts with a repository to fetch data. The query parameter 'limit' has a default value and a constraint. ```typescript import {HelloRepository} from '../repositories'; import {HelloMessage} from '../models'; import {get, param} from '@loopback/rest'; import {repository} from '@loopback/repository'; export class HelloController { constructor( @repository(HelloRepository) protected repository: HelloRepository, ) {} // returns a list of our objects @get('/messages') async list(@param.query.number('limit') limit = 10): Promise { if (limit > 100) limit = 100; // your logic return this.repository.find({limit}); // a CRUD method from our repository } } ``` -------------------------------- ### Boot and Start Express Server for Tests Source: https://github.com/loopbackio/loopback-next/blob/master/examples/lb3-application/README.md This code block demonstrates how to boot and start the Express server in a 'before' hook and stop it in an 'after' hook for acceptance tests. This is essential for setting up the test environment. ```typescript describe('LoopBack 3 style tests - Launch Express server', function () { before(async function () { app = new ExpressServer(); await app.boot(); await app.start(); }); after(async () => { await app.stop(); }); // your tests here runTests(); }); ``` -------------------------------- ### Start LoopBack Application Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Troubleshooting.md Use `npm start` to run your LoopBack application. This command also enables viewing stack traces and console output for easier debugging. ```bash cd myapp npm start ``` -------------------------------- ### Create Parameterized Controller Class Factory Source: https://github.com/loopbackio/loopback-next/blob/master/docs/site/Controller.md This example demonstrates a factory function that creates a controller class with parameterized decorations. The `@api` decorator is applied with a basePath derived from function arguments, and the `@get` decorator uses a version string also passed as an argument. This pattern allows for dynamic configuration of controllers. ```typescript function createControllerClass(version: string, basePath: string) { @api({basePath: `${basePath}`}) class Controller { @get(`/${version}`) find() {} } } ``` -------------------------------- ### Basic Application Bootstrapping Source: https://github.com/loopbackio/loopback-next/blob/master/packages/boot/README.md Extend Application with BootMixin and use app.boot() to initialize booters. Ensure projectRoot is set before calling app.boot(). ```typescript import {Application} from '@loopback/core'; import {BootMixin, Booter, Binding} from '@loopback/boot'; class BootApp extends BootMixin(Application) {} const app = new BootApp(); app.projectRoot = __dirname; await app.boot(); await app.start(); ``` -------------------------------- ### Install @loopback/filter Source: https://github.com/loopbackio/loopback-next/blob/master/packages/filter/README.md Install the @loopback/filter package using npm. If you have already installed @loopback/repository, you can import from there instead. ```sh npm install --save @loopback/filter ```