API Mock for Angular
Mock API calls while development, testing or building an example library. Define results based on url pattern and if needed http methods.
Installation
npm install ngx-api-mock --save
Usage
Import NgxApiMockModule
into your app's modules:
import { NgxApiMockModule } from 'ngx-api-mock';
@NgModule({
imports: [
NgxApiMockModule.forRoot(config)
]
})
Configuration
string[]
urlParts: Trigger api mock interceptor for any url wich contain on part of the list.
{pattern: string; response: any; method?: HttpMethod; delay: number;}[]
rules: Matching url based on pattern and if set method to return result.
Examples
@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
},
],
})
]
})
Changelog
v3.0.0
- BREAKING: Update to Angular 12
v2.0.0
- BREAKING: Update to Angular 11
- Output request params to console for each request