Numerous Packages Multiply
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

@loopback/rest

0.19.4 • Public • Published

@loopback/rest

The REST API package for loopback-next.

Overview

This component provides a REST server for your application instances, complete with:

  • new custom routing engine (special thanks to @bajtos)!
  • tools for defining your application routes
  • OpenAPI 3.0 spec (openapi.json/openapi.yaml) generation using @loopback/openapi-v3
  • a default sequence implementation to manage the request and response lifecycle

Installation

To use this package, you'll need to install @loopback/rest.

npm i @loopback/rest

Basic Use

Here's a basic "Hello World" application using @loopback/rest:

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 rest = await app.getServer(RestServer);
  const port = await server.get('rest.port');
  console.log(`Server is running at http://127.0.0.1:${port}`);
})();

Configuration

The rest package is configured by passing a rest property inside of your Application options.

const app = new RestApplication({
  rest: {
    port: 3001,
  },
});

rest options

Property Type Purpose
port number Specify the port on which the RestServer will listen for traffic.
sequence SequenceHandler Use a custom SequenceHandler to change the behavior of the RestServer for the request-response lifecycle.

Contributions

Tests

Run npm test from the root folder.

Contributors

See all contributors.

License

MIT

Keywords

none

install

npm i @loopback/rest

Downloadsweekly downloads

2,315

version

0.19.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability