angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 231 forks source link

multiple microservices? #119

Closed el-davo closed 7 years ago

el-davo commented 7 years ago

Hi, I am working in an environment where we are using multiple backend microservices, We have a gateway in front of all the microservices which maps requests to each one.

From the front-end perspective the api calls would be

/gateway/microservice1/resource /gateway/microservice2/resource

Ive been trying the following

import { ReleaseToggle } from '../../app/release-toggles/release-toggles.state';
import { InMemoryDbService } from 'angular-in-memory-web-api';

export class ReleaseTogglesStub implements InMemoryDbService {
    createDb() {
        let microservice1Resource= [{}, {}, {}];
       let microservice2Resource= [{}, {}, {}];
        return {microservice1Resource, microservice2Resource};
    }
}

And added apiBase as '/gateway'

However the above does not map correctly when the stubs are removed. So the above would map to

/gateway/microservice1/ /gateway/microservice2/

Is it possible with this library to nest resources into microservice?, something like

import { ReleaseToggle } from '../../app/release-toggles/release-toggles.state';
import { InMemoryDbService } from 'angular-in-memory-web-api';

export class ReleaseTogglesStub implements InMemoryDbService {
    createDb() {
        let microservice1Resource= [{}, {}, {}];
       let microservice2Resource= [{}, {}, {}];
        return {microservice1: {microservice1Resource}, microservice2: {microservice2Resource}};
    }
}

which would then map correctly to

/gateway/microservice1/resource /gateway/microservice2/resource

wardbell commented 7 years ago

Sorry but I'll have to close this as it is outside the limited design goals for this library.

However, here's a little know fact: the in-mem web api actually doesn't care about the first part of the URL. It only cares about the uniqueness of the resource name. So you can get away with

/microservice1/foo
/microservice2/bar

as long as the resource names are unique w/o regard to the path leading to them.

You can also override the parseUrl and do almost any wacky thing you want. There's an example in the source code.

I've added tests in PR #130 which may be a good resource for you.