import { inject } from '@loopback/core' ; import { GreetingService , GREETING_SERVICE , } from '@loopback/example-greeter-extension' ; import { get , param , Request , RestBindings } from '@loopback/rest' ; import { Message } from '../types' ; export class GreetingController { constructor ( @ inject ( GREETING_SERVICE ) private greetingService , @ inject ( RestBindings . Http . REQUEST ) private request ) { } @ get ( '/greet/{name}' , { responses : { '200' : { description : '' , content : { 'application/json' : { schema : { type : 'object' , properties : { timestamp : 'string' , language : 'string' , message : 'string' , } , } , } , } , } , } , } ) async greet ( @ param . path . string ( 'name' ) name ) { const language = this . request . acceptsLanguages ( [ 'en' , 'zh' ] ) || 'en' ; const greeting = await this . greetingService . greet ( language , name ) ; return { timestamp : new Date ( ) , language , greeting , } ; } }