How to use the @loopback/rest.get 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 / packages / boot / src / __tests__ / fixtures / multiple.artifact.ts View on Github external
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/boot
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {get} from '@loopback/rest';

export class ArtifactOne {
  @get('/one')
  one() {
    return 'ControllerOne.one()';
  }
}

export class ArtifactTwo {
  @get('/two')
  two() {
    return 'ControllerTwo.two()';
  }
}

export function hello() {
  return 'hello world';
}
github dofapi / dofapi / server / src / controllers / set-equipments.controller.ts View on Github external
requestBody,
} from '@loopback/rest';
import { Equipment } from '../models';


export class SetEquipmentsController {
  constructor(
    @repository(SetRepository) protected setRepo: SetRepository,
  ) { }

  // @post('/sets/{id}/equipments')
  // async create(@param.path.number('id') id: number, @requestBody() equipment: Equipment) {
  //   return await this.setRepo.equipments(id).create(equipment);
  // }

  @get('/set/{id}/equipments', {
    responses: {
      '200': {
        description: "Array of equipment's belonging to set",
        content: {
          'application/json': {
            schema: { type: 'array', items: { 'x-ts-type': Equipment } },
          },
        },
      },
    },
  })
  async find(
    @param.path.number('id') id: number,
    @param.query.object('filter') filter?: Filter,
  ): Promise {
    return await this.setRepo.equipments(id).find(filter);
github strongloop / loopback4-example-shopping / packages / shopping / src / controllers / ping.controller.ts View on Github external
additionalProperties: false,
          },
        },
      },
    },
  },
};

/**
 * A simple controller to bounce back http requests
 */
export class PingController {
  constructor(@inject(RestBindings.Http.REQUEST) private req: Request) {}

  // Map to `GET /ping`
  @get('/ping', {
    responses: {
      '200': PING_RESPONSE,
    },
  })
  ping(): object {
    // Reply with a greeting, the current time, the url, and request headers
    return {
      greeting: 'Hello from LoopBack',
      date: new Date(),
      url: this.req.url,
      headers: Object.assign({}, this.req.headers),
    };
  }
}
github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list-image.controller.ts View on Github external
'200': {
        description: 'create todoListImage model instance',
        content: {
          'application/json': {schema: getModelSchemaRef(TodoListImage)},
        },
      },
    },
  })
  async create(
    @param.path.number('id') id: number,
    @requestBody() image: TodoListImage,
  ): Promise {
    return this.todoListRepo.image(id).create(image);
  }

  @get('/todo-lists/{id}/image', {
    responses: {
      '200': {
        description: 'The image belonging to the TodoList',
        content: {
          'application/json': {
            schema: getModelSchemaRef(TodoListImage, {includeRelations: true}),
          },
        },
      },
    },
  })
  async find(@param.path.number('id') id: number): Promise {
    return this.todoListRepo.image(id).get();
  }
}
github sourcefuse / loopback4-starter / src / modules / auth / login.controller.ts View on Github external
callbackURL: process.env.GOOGLE_AUTH_CALLBACK_URL,
      clientID: process.env.GOOGLE_AUTH_CLIENT_ID,
      clientSecret: process.env.GOOGLE_AUTH_CLIENT_SECRET,
      tokenURL: process.env.GOOGLE_AUTH_TOKEN_URL,
    },
    (req: Request) => {
      return {
        accessType: 'offline',
        state: Object.keys(req.query)
          .map(key => `${key}=${req.query[key]}`)
          .join('&'),
      };
    },
  )
  @authorize(['*'])
  @get('/auth/google-auth-redirect', {
    responses: {
      [STATUS_CODE.OK]: {
        description: 'Token Response',
        content: {
          [CONTENT_TYPE.JSON]: {
            schema: {'x-ts-type': TokenResponse},
          },
        },
      },
    },
  })
  async googleCallback(
    @param.query.string('code') code: string,
    @param.query.string('state') state: string,
    @inject(RestBindings.Http.RESPONSE) response: Response,
  ): Promise {
github strongloop / loopback-next / examples / todo-list / src / controllers / todo.controller.ts View on Github external
'application/json': {
            schema: getModelSchemaRef(Todo, {includeRelations: true}),
          },
        },
      },
    },
  })
  async findTodoById(
    @param.path.number('id') id: number,
    @param.query.object('filter', getFilterSchemaFor(Todo))
    filter?: Filter,
  ): Promise {
    return this.todoRepo.findById(id, filter);
  }

  @get('/todos', {
    responses: {
      '200': {
        description: 'Array of Todo model instances',
        content: {
          'application/json': {
            schema: {
              type: 'array',
              items: getModelSchemaRef(Todo, {includeRelations: true}),
            },
          },
        },
      },
    },
  })
  async findTodos(
    @param.query.object('filter', getFilterSchemaFor(Todo))
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / character.controller.ts View on Github external
@post('/characters/login', {
    responses: {
      '200': {
        description: 'Token',
        content: {},
      },
    },
  })
  async login(
    @requestBody(CredentialsRequestBody) credential: Credential,
  ): Promise<{token: string}> {
    const token = await this.jwtService.getToken(credential);
    return {token};
  }

  @get('/characters/me', {
    responses: {
      '200': {
        description: 'The current user profile',
        content: {
          'application/json': {
            schema: UserProfileSchema,
          },
        },
      },
    },
  })
  @authenticate('jwt', {required: [PermissionKey.ViewOwnUser]})
  async printCurrentUser(): Promise {
    return this.getCurrentUser();
  }
github strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
}

    @get('/{id}', {
      ...response.model(200, `${modelName} instance`, modelCtor, {
        includeRelations: true,
      }),
    })
    async findById(
      @param(idPathParam) id: IdType,
      @param.query.object('filter', getFilterSchemaFor(modelCtor))
      filter?: Filter,
    ): Promise {
      return this.repository.findById(id, filter);
    }

    @get('/count', {
      ...response(200, `${modelName} count`, {schema: CountSchema}),
    })
    async count(
      @param.query.object('where', getWhereSchemaFor(modelCtor))
      where?: Where,
    ): Promise {
      return this.repository.count(where);
    }

    @patch('/', {
      ...response(200, `Count of ${modelName} models updated`, {
        schema: CountSchema,
      }),
    })
    async updateAll(
      @body(modelCtor, {partial: true}) data: Partial,
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / admin.controller.ts View on Github external
PermissionKey.DeleteAnyUser];
      if (await this.characterRepository.exists(character.email)){
        throw new HttpErrors.BadRequest(`This email already exists`);
      }
      else {
        const savedCharacter = await this.characterRepository.create(character);
        delete savedCharacter.password;
        return savedCharacter;
      }
  }

  /**
   * count character
   * @param where filter
   */
  @get('/admin/characters/count', {
    responses: {
      '200': {
        description: 'Character model count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  @authenticate('jwt', {"required": [PermissionKey.ViewAnyUser]})
  async count(
    @param.query.object('where', getWhereSchemaFor(Character)) where?: Where,
  ): Promise {
    return await this.characterRepository.count(where);
  }

  /**
   * show all character
github sourcefuse / loopback4-starter / src / modules / audit / audit-log.controller.ts View on Github external
description: 'AuditLog PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody() auditLog: AuditLog,
    @param.query.object('where', getWhereSchemaFor(AuditLog))
    where?: Where,
  ): Promise {
    return await this.auditLogRepository.updateAll(auditLog, where);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.ViewAudit])
  @get('/audit-logs/{id}', {
    responses: {
      '200': {
        description: 'AuditLog model instance',
        content: {'application/json': {schema: {'x-ts-type': AuditLog}}},
      },
    },
  })
  async findById(@param.path.number('id') id: number): Promise {
    return await this.auditLogRepository.findById(id);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.UpdateAudit])
  @patch('/audit-logs/{id}', {
    responses: {
      '204': {