// Copyright IBM Corp. and LoopBack contributors 2019. All Rights Reserved. // Node module: @loopback/example-express-composition // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import {inject} from '@loopback/core'; import {get, Request, ResponseObject, RestBindings} from '@loopback/rest'; /** * OpenAPI response for ping() */ const PING_RESPONSE: ResponseObject = { description: 'Ping Response', content: { 'application/json': { schema: { type: 'object', title: 'PingResponse', properties: { greeting: {type: 'string'}, date: {type: 'string'}, url: {type: 'string'}, headers: { type: 'object', properties: { 'Content-Type': {type: 'string'}, }, additionalProperties: true, }, }, }, }, }, }; /** * 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), }; } }