1 | # @loopback/core
|
2 |
|
3 | LoopBack makes it easy to build modern applications that require complex
|
4 | integrations.
|
5 |
|
6 | ## Overview
|
7 |
|
8 | - Fast, small, powerful, extensible core
|
9 | - Generate real APIs with a single command
|
10 | - Define your data and endpoints with OpenAPI
|
11 | - No maintenance of generated code
|
12 |
|
13 | ## Installation
|
14 |
|
15 | ```shell
|
16 | $ npm install --save @loopback/core
|
17 | ```
|
18 |
|
19 | ## Basic Use
|
20 |
|
21 | `@loopback/core` provides the foundation for your LoopBack app, but unlike
|
22 | previous versions, it no longer contains the implementation for listening
|
23 | servers.
|
24 |
|
25 | For a typical example of how to create a REST server with your application, see
|
26 | the
|
27 | [@loopback/rest package.](https://github.com/loopbackio/loopback-next/tree/master/packages/rest)
|
28 |
|
29 | ## Advanced Use
|
30 |
|
31 | Since `@loopback/core` is decoupled from the listening server implementation,
|
32 | LoopBack applications are now able to work with any component that provides this
|
33 | functionality.
|
34 |
|
35 | ```ts
|
36 | // index.ts
|
37 | import {Application} from '@loopback/core';
|
38 | import {RestComponent} from '@loopback/rest';
|
39 | import {GrpcComponent} from '@loopback/grpc';
|
40 |
|
41 | const app = new Application({
|
42 | rest: {
|
43 | port: 3000,
|
44 | },
|
45 | grpc: {
|
46 | port: 3001,
|
47 | },
|
48 | });
|
49 | app.component(RestComponent); // REST Server
|
50 | app.component(GrpcComponent)(
|
51 | // GRPC Server
|
52 |
|
53 | async function start() {
|
54 | // Let's retrieve the bound instances of our servers.
|
55 | const rest = await app.getServer<RestServer>('RestServer');
|
56 | const grpc = await app.getServer<GrpcServer>('GrpcServer');
|
57 |
|
58 | // Define all sorts of bindings here to pass configuration or data
|
59 | // between your server instances, define controllers and datasources for them,
|
60 | // etc...
|
61 | await app.start(); // This automatically spins up all your servers, too!
|
62 | console.log(`REST server running on port: ${rest.getSync('rest.port')}`);
|
63 | console.log(`GRPC server running on port: ${grpc.getSync('grpc.port')}`);
|
64 | },
|
65 | )();
|
66 | ```
|
67 |
|
68 | In the above example, having a GRPC server mounted on your Application could
|
69 | enable communication with other GRPC-enabled microservices, allowing things like
|
70 | dynamic configuration updates.
|
71 |
|
72 | ## Contributions
|
73 |
|
74 | - [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
|
75 | - [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
|
76 |
|
77 | ## Tests
|
78 |
|
79 | Run `npm test` from the root folder.
|
80 |
|
81 | ## Contributors
|
82 |
|
83 | See
|
84 | [all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
|
85 |
|
86 | ## License
|
87 |
|
88 | MIT
|