Page Contents
In LoopBack 4, a Service class provides access to additional functionality.
- Local services are used to implement “utility” functionality, for example obtain a JWT authentication token for a given user.
- Service proxies are used to access 3rd-party web services (e.g. REST or SOAP), as further explained in Calling other APIs and web services
In an application, a new service is typically created by running
lb4 service
.
Components can contribute local services as follows.
- Run
lb4 service
and choose eitherLocal service class
orLocal service provider
as the service type to create. - In your component constructor, create a service binding and add it to the list of bindings contributed by the component to the target application class.
An example showing how to build a component contributing a local service class
(MyService
) and a local service provider (GeocodeServiceProvider
):
import {createServiceBinding} from '@loopback/core';
import {MyService} from './services/my.service.ts';
import {GeocodeServiceProvider} from './services/geocoder.service.ts';
export class SampleComponent implements Component {
bindings = [
createServiceBinding(MyService),
createServiceBinding(GeocoderServiceProvider),
];
}