This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

ngx-api-mock
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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

urlParts: string[]

Trigger api mock interceptor for any url wich contain on part of the list.

rules: {pattern: string; response: any; method?: HttpMethod; delay: number;}[]

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

Package Sidebar

Install

npm i ngx-api-mock

Weekly Downloads

1

Version

3.0.0

License

MIT

Unpacked Size

34.8 kB

Total Files

22

Last publish

Collaborators

  • thrintelen