Registry / testing / angular-in-memory-web-api

angular-in-memory-web-api

JSON →
library0.21.0jsnpmunverified

An in-memory web API for Angular demos and tests, version 0.21.0. This package simulates a REST API backend for prototyping and testing Angular applications without a real server. It intercepts HttpClient requests and responds with mock data. Supported by the Angular team, it follows Angular's release cadence. Different from full mock libraries (e.g., json-server), it integrates directly with Angular's HTTP interceptors and dependency injection, making it seamless for development and testing. Note: It requires Angular 21+ and rxjs 6.5.3+ or 7.4.0+. Types included.

npm install angular-in-memory-web-api
INSTALL
IMPORT
SIG · ANGULAR-IN-MEMORY-
A
angular-in-memory-web-api
testingjavascriptv0.21.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpClientInMemoryWebApiModule
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
const HttpClientInMemoryWebApiModule = require('angular-in-memory-web-api').HttpClientInMemoryWebApiModule;
ESM-only. Cannot use require().
InMemoryDbService
import { InMemoryDbService } from 'angular-in-memory-web-api';
Interface to implement for mock data.
RequestInfo
import { RequestInfo } from 'angular-in-memory-web-api';
For custom request handling.
InMemoryWebApiModule
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
InMemoryWebApiModule is deprecated; use HttpClientInMemoryWebApiModule.

Shows how to create an in-memory database service and register it with the module.

import { Injectable } from '@angular/core'; import { InMemoryDbService } from 'angular-in-memory-web-api'; @Injectable({ providedIn: 'root' }) export class InMemoryDataService implements InMemoryDbService { createDb() { const heroes = [ { id: 12, name: 'Dr. Nice' }, { id: 13, name: 'Bombasto' }, { id: 14, name: 'Celeritas' } ]; return { heroes }; } } // In AppModule: import { HttpClientModule } from '@angular/common/http'; import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api'; import { InMemoryDataService } from './in-memory-data.service'; @NgModule({ imports: [ HttpClientModule, HttpClientInMemoryWebApiModule.forRoot( InMemoryDataService, { delay: 500, dataEncapsulation: false } ) ] }) export class AppModule { }
Debug
Known issues
deprecatedInMemoryWebApiModule has been deprecated since v0.15. Use HttpClientInMemoryWebApiModule instead.
fix
Replace InMemoryWebApiModule with HttpClientInMemoryWebApiModule.
affects: >=0.15
breakingIn v0.21, peer dependencies require Angular 21+. Installation will fail with older Angular versions.
fix
Upgrade to Angular 21 or use an older version of angular-in-memory-web-api (e.g., 0.20.x).
affects: >=0.21
gotchaDo not use InMemoryWebApiModule in production. It is intended for development and testing only.
fix
Remove the import in production builds or use environment flags.
affects: >=0.0
gotchaThe library suppresses actual HTTP requests; your app will not make real API calls. Ensure you only enable it in non-production environments.
fix
Use Angular environment configuration to conditionally import the module.
affects: >=0.0
gotchaIf dataEncapsulation is true (default), the response is wrapped in a 'data' property. Many examples set it to false for simpler responses.
fix
Set dataEncapsulation: false in options if you want raw array responses.
affects: >=0.0
Errors
Common errors & fixes
Error: Cannot find module 'angular-in-memory-web-api'
Package not installed or import path incorrect.
fix
Run 'npm install angular-in-memory-web-api --save-dev'.
NullInjectorError: No provider for InMemoryDbService!
Missing InMemoryDataService class or forgot to pass it to .forRoot().
fix
Implement InMemoryDbService and pass the class to HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService).
Error: Unexpected value 'HttpClientInMemoryWebApiModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
Incorrect import: using deprecated InMemoryWebApiModule or wrong module.
fix
Import HttpClientInMemoryWebApiModule from 'angular-in-memory-web-api'.
TypeError: Cannot read properties of undefined (reading 'heroes')
createDb() returns an object with property name not matching the URL path.
fix
Ensure the property name in createDb() matches the resource name in your service (e.g., 'heroes' for /api/heroes).
Upgrade
Version history
0.21.0latest on npm
Audit
Dependencies
@angular/corerequiredPeer dependency: provides Angular dependency injection and services.
@angular/commonrequiredPeer dependency: provides HttpClient and other common modules.
rxjsrequiredPeer dependency: required for Observables used by HttpClient.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
angular-in-memory-web-api — npm install angular-in-memory-web-api · libregistry