Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of services with controllers (technical preview) #1267

Closed
b-admike opened this issue Apr 19, 2018 · 12 comments
Closed

Integration of services with controllers (technical preview) #1267

b-admike opened this issue Apr 19, 2018 · 12 comments
Milestone

Comments

@b-admike
Copy link
Contributor

b-admike commented Apr 19, 2018

Description

Explore how service integration works with controllers. This task is an outcome of #1069.

Use case

A controller needs to invoke a REST API or SOAP web service.

export class ShoppingController {

  @serviceProxy('pricingService')
  private pricingService: pricingService;

  @serviceProxy('shippingService')
  private shippingService: ShippingService;
}

Or

export class ShoppingController {
  constructor(
    @serviceProxy('pricingService')  private pricingService: pricingService,
    @serviceProxy('shippingService') private shippingService: ShippingService
  ) {}
}

We'll configure two datasources and bind them to the context.

  • pricingService: REST API
  • shippingService: SOAP Web Service API
context.bind('dataSources.pricingService').to(...);
context.bind('dataSources.shippingService').to(...);

Acceptance Criteria

  • Controllers can use @serviceProxy decorator for constructor parameters or properties to inject a service proxy for backend services
  • The service proxy can be resolved from data source name or instance
  • The service proxy can be optionally typed with a hand-written TS type/interface
@b-admike b-admike added this to the May Milestone milestone Apr 27, 2018
@shimks
Copy link
Contributor

shimks commented Apr 30, 2018

@raymondfeng Could you update the acceptance criteria for estimation? Thanks

@raymondfeng
Copy link
Contributor

@shimks Updated

@virkt25
Copy link
Contributor

virkt25 commented May 1, 2018

Is the Service assumed to be created using LB3 constructs? (strong-remoting / strong-soap)?

@virkt25 virkt25 removed their assignment May 1, 2018
@b-admike
Copy link
Contributor Author

b-admike commented May 1, 2018

Looking at the PR we have for the weakly typed service integration spike, we already have the serviceProxy decorator and have a test using it with a controller as shown above. What else do we need to for this ticket?

Is the Service assumed to be created using LB3 constructs? (strong-remoting / strong-soap)?

Yeah I think so (see https://github.com/strongloop/loopback-next/pull/1119/files#diff-acfd88705f55f0e2f6831937a276b7fbR19).

@b-admike b-admike removed their assignment May 1, 2018
@raymondfeng
Copy link
Contributor

The PR is feature complete and ready for review.

@bajtos
Copy link
Member

bajtos commented May 4, 2018

Cross-posting from #1069 (comment):

IMO, the pull request #1119 is only a part of the overall story. While it makes it easy to consume services in controllers, it omits other important use cases.

1] When consuming a service using REST connector with template-based configuration: As an app developer, I would definitely want to have few smoke tests to verify that my templates work as intended and match the API provided by the service at the other side. I would like to write an integration test that's using only the service (not the full app!), something along the following lines:

import {GeoService} from '../services/geo.service';
import {expect} from '@loopback/testlab';

describe('GeoService', () => {
  let service: GeoService;
  beforeEach(() => service = new GeoService());

  describe('geocode', () => {
    it('returns geo coords for a given address', () => {
      const result = await service.geocode('107 S B St', 'San Mateo', '94401');
      // { lat: 37.5669986, lng: -122.3237495 }
     expect(result.lat).approximately(37.5669986, 0.5);
     expect(result.lng).approximately(-122.3237495, 0.5);
    });
  });
});

2] There should be also a new CLI command for creating services, this command should:

  • Create the datasource.
  • Create any artifacts needed to register the service with the app for dependency injection. This may require us to implement support for services in @loopback/boot.
  • Create any artifacts needed to write an integration test for the service as I shown above.
  • Ideally, include a scaffolding making it easier for app developers to start writing smoke tests.

@shimks
Copy link
Contributor

shimks commented May 7, 2018

@bajtos Although I agree that what you're proposing should be done as an outcome of the spike, IMO this is out of scope for what we have estimated and I feel that it should live in its own issue to be estimated and groomed.

@dhmlau
Copy link
Member

dhmlau commented May 8, 2018

PR: #1119

@bajtos
Copy link
Member

bajtos commented May 9, 2018

@shimks you are right, I agree scope creep is bad. At the same time, I don't want us to release a half-baked feature that's difficult to use.

I am going to:

@bajtos bajtos changed the title Integration of services with controllers Integration of services with controllers (technical preview) May 9, 2018
@shimks
Copy link
Contributor

shimks commented May 9, 2018

@raymondfeng Is the (technical preview) feature complete? If so, can you close it please?

@bajtos
Copy link
Member

bajtos commented May 16, 2018

Closing as done.

@bajtos bajtos closed this as completed May 16, 2018
@bajtos bajtos added the p1 label Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants