New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

xloop

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xloop

Add sugar & enhanced APIs inspired by NestJS to Loopback v4

  • 0.1.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

xloop

Add sugar & enhanced APIs inspired by NestJS to Loopback v4

Installation

  • Nodejs >= 10
  • Loopback 4
npm install xloop

API Reference

  • HTTP Decorators
    • @http.request()
    • @http.response()
    • @http.header(string, string)
    • @http.status(number)
    • @http.context()
  • Custom Error Codes

HTTP Decorators

HTTP decorators are used to annotate controller methods.

@http.request()

Decorate a param of a controller method to get the request object.

import { http } from 'xloop/decorators';

export class SomeController {
  sayHello(@http.request() req: Request) {}
}

@http.response()

Decorate a param of a controller method to get the response object.

import { http } from 'xloop/decorators';

export class SomeController {
  sayHello(@http.response() res: Response) {}
}

@http.header(string, string)

Decorate a controller method to specify a custom response header.

import { http } from 'xloop/decorators';

export class SomeController {
  @http.header('Cache-Control', 'no-cache')
  sayHello() {}
}

You can apply multiple header decorators to the method for more custom headers:

import { http } from 'xloop/decorators';

export class SomeController {
  @http.header('Cache-Control', 'no-cache')
  @http.header('X-Hello', 'Hello World')
  sayHello() {}
}

@http.status(number)

Decorate a controller method to change the status code of the response statically.

import { http } from 'xloop/decorators';

export class SomeController {
  @http.status(202)
  sayHello() {}
}

@http.context()

Decorate a param of a controller method to get the context object.

import { http } from 'xloop/decorators';

export class SomeController {
  sayHello(@http.context() ctx: Context) {}
}

Custom Error Codes

Loopback v4 defines a few error codes and we can set up our own codes:

const ENTITY_DUPLICATED = 'ENTITY_DUPLICATED';
class EntityDuplicatedError extends Error {
  ...
  code = ENTITY_DUPLICATED;
}

class Application extends RestApplication {
  constructor(...) {
    ...
    this.configure(RestBindings.SequenceActions.REJECT).to(
      {
        [ENTITY_DUPLICATED]: 422,
      },
    );
  }
}

Keywords

FAQs

Package last updated on 29 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc