Mock API calls while development, testing or building an example library. Define results based on url pattern and if needed http methods.
npm install ngx-api-mock --save
Import NgxApiMockModule
into your app's modules:
import { NgxApiMockModule } from 'ngx-api-mock';
@NgModule({
imports: [
NgxApiMockModule.forRoot(config)
]
})
Trigger api mock interceptor for any url wich contain on part of the list.
Matching url based on pattern and if set method to return result.
@NgModule({
imports: [
NgxApiMockModule.forRoot({
urlParts: ['thorsten-rintelen.de/v1/'],
rules: [
{
pattern: 'users/\\d+',
response: 'success',
method: 'POST',
},
{
pattern: 'users/\\d+',
response: true,
method: 'DELETE',
delay: 2000
},
],
})
]
})
ng serve