UNPKG

1.73 kBMarkdownView Raw
1# @loopback/rest
2
3The REST API package for
4[loopback-next](https://github.com/loopbackio/loopback-next).
5
6## Overview
7
8This component provides a REST server for your application instances, complete
9with:
10
11- new custom routing engine (special thanks to @bajtos)!
12- tools for defining your application routes
13- OpenAPI 3.0 spec (`openapi.json`/`openapi.yaml`) generation using
14 `@loopback/openapi-v3`
15- a default sequence implementation to manage the request and response lifecycle
16
17**NOTE: Starting from 6.0.0, we have introduced a middleware-based sequence,
18which is is used as the default one for newly generated LoopBack applications
19using `lb4` command from `@loopback/cli`.**
20
21## Installation
22
23To use this package, you'll need to install `@loopback/rest`.
24
25```sh
26npm i @loopback/rest
27```
28
29## Basic Use
30
31Here's a basic "Hello World" application using `@loopback/rest`:
32
33```ts
34import {RestApplication, RestServer} from '@loopback/rest';
35
36const app = new RestApplication();
37app.handler(({request, response}, sequence) => {
38 sequence.send(response, 'hello world');
39});
40
41(async function start() {
42 await app.start();
43
44 const server = await app.getServer(RestServer);
45 const port = await server.get('rest.port');
46 console.log(`Server is running at http://127.0.0.1:${port}`);
47})();
48```
49
50## Configuration
51
52See https://loopback.io/doc/en/lb4/Server.html#configuration.
53
54## Contributions
55
56- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
57- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
58
59## Tests
60
61Run `npm test` from the root folder.
62
63## Contributors
64
65See
66[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
67
68## License
69
70MIT