How to use the @loopback/rest.RestBindings.Http function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / examples / greeting-app / src / interceptors / caching.interceptor.ts View on Github external
return async (
      ctx: InvocationContext,
      next: () => ValueOrPromise,
    ) => {
      const httpReq = await ctx.get(RestBindings.Http.REQUEST, {
        optional: true,
      });
      /* istanbul ignore if */
      if (!httpReq) {
        // Not http request
        return next();
      }
      const key = httpReq.path;
      const lang = httpReq.acceptsLanguages(['en', 'zh']) || 'en';
      const cachingKey = `${lang}:${key}`;
      const cachedResult = await this.cachingService.get(cachingKey);
      if (cachedResult) {
        debug('Cache found for %s %j', cachingKey, cachedResult);
        return cachedResult;
      }
      const result = await next();
github strongloop / loopback-next / packages / v3compat / src / remoting / lb3-model-controller.ts View on Github external
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';

const debug = debugFactory('loopback:v3compat:rest-adapter');

export class Lb3ModelController {
  @inject(RestBindings.Http.REQUEST)
  protected request: Request;

  @inject(RestBindings.Http.RESPONSE)
  protected response: Response;

  // TODO: a property for strong-remoting's HttpContext

  [key: string]: Function | Request | Response;

  protected buildMethodArguments(
    sharedMethod: SharedMethod,
    inputArgs: OperationArgs,
  ) {
    const finalArgs: OperationArgs = [];
    for (const argSpec of sharedMethod.accepts) {
      const source = argSpec.http && argSpec.http.source;
      switch (source) {
        case 'req':
          finalArgs.push(this.request);
github strongloop / loopback-next / packages / v3compat / src / remoting / lb3-model-controller.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';

const debug = debugFactory('loopback:v3compat:rest-adapter');

export class Lb3ModelController {
  @inject(RestBindings.Http.REQUEST)
  protected request: Request;

  @inject(RestBindings.Http.RESPONSE)
  protected response: Response;

  // TODO: a property for strong-remoting's HttpContext

  [key: string]: Function | Request | Response;

  protected buildMethodArguments(
    sharedMethod: SharedMethod,
    inputArgs: OperationArgs,
  ) {
    const finalArgs: OperationArgs = [];
    for (const argSpec of sharedMethod.accepts) {
      const source = argSpec.http && argSpec.http.source;
github strongloop / loopback-next / examples / todo / src / sequence.ts View on Github external
constructor(
    @inject(RestBindings.Http.CONTEXT) public ctx: Context,
    @inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
    @inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
    @inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
    @inject(SequenceActions.SEND) public send: Send,
    @inject(SequenceActions.REJECT) public reject: Reject,
  ) {}
github IBM / blockchainbean2 / web-app / src / controllers / shipper.controller.ts View on Github external
  constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { }
github strongloop / loopback4-example-shopping / src / controllers / home-page.controller.ts View on Github external
constructor(
    @inject(PackageKey) private pkg: PackageInfo,
    @inject(RestBindings.Http.RESPONSE) private response: Response,
  ) {
    const html = fs.readFileSync(
      path.join(__dirname, '../../../public/index.html.template'),
      'utf-8',
    );
    this.render = template(html);
  }
github strongloop / loopback-next / packages / rest-explorer / src / rest-explorer.controller.ts View on Github external
constructor(
    @inject(RestBindings.CONFIG, {optional: true})
    restConfig: RestServerConfig = {},
    @inject(RestExplorerBindings.CONFIG, {optional: true})
    explorerConfig: RestExplorerConfig = {},
    @inject(RestBindings.BASE_PATH) private serverBasePath: string,
    @inject(RestBindings.SERVER) private restServer: RestServer,
    @inject(RestBindings.Http.CONTEXT) private requestContext: RequestContext,
  ) {
    this.useSelfHostedSpec = explorerConfig.useSelfHostedSpec !== false;
    this.openApiSpecUrl = this.getOpenApiSpecUrl(restConfig);
  }
github dofapi / dofapi / server / src / controllers / ping.controller.ts View on Github external
  constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { }