miragejs / discuss

Ask questions, get help, and share what you've built with Mirage
MIT License
2 stars 0 forks source link

Is it possible to use a combination of mock API's and actual API calls ? #58

Open Jayadev6191 opened 3 years ago

Jayadev6191 commented 3 years ago

Example:

If my app requires two API calls

  1. /getFavFruit -> (yet to be implemented)
  2. /getFavDrink -> (Implemented)

If the implementation of getFavDrink is ready is it possible to only mock getFavFruit API using miragejs and continue to make real network calls to getFavDrink endpoint ?

export function makeServer({ environment = 'test' }) {
    return createServer({
        environment,

        routes() {
             this.get('/getFavFruit', () => 'apple');
        },
    });
}

When I have the above code in my server.js file I'm not able to make real network calls to /getFavDrink endpoint.

Does this mean, miragejs intercepts all the network calls even if they are not mocked in the routes?

lincoln-pahwa commented 3 years ago

You can use passthrough:

export function makeServer({ environment = 'test' }) {
    return createServer({
        environment,

        routes() {
             this.get('/getFavFruit', () => 'apple');
             // passthrough
             this.passthrough('/getFavDrink');
        },
    });
}