This in-memory-web-api exists primarily to support the Angular documentation. It is not supposed to emulate every possible real world web API and is not intended for production use.
Most importantly, it is always experimental.
We will make breaking changes and we won't feel bad about it
because this is a development tool, not a production product.
We do try to tell you about such changes in this CHANGELOG.md
and we fix bugs as fast as we can.
- update to support Angular v10.
- no functional changes.
- update to support Angular version 8.x and forward
- no functional changes
- remove
@angular/http
support - no functional changes
BREAKING CHANGE
This version no longer supports any functionality for @angular/http
. Please use
@angular/common/http
instead.
- update to support Angular v7.
- no functional changes
- update to Angular and RxJS v6 releases
Migrate to Angular v6 and RxJS v6 (rc and beta)
Note that this release is pinned to Angular "^6.0.0-rc.0" and RxJS "^6.0.0-beta.1". Will likely update again when they are official.
BREAKING CHANGE This version depends on RxJS v6 and is not backward compatible with earlier RxJS versions.
Simulated HTTP error responses were not delaying the prescribed time when using RxJS delay()
because it was short-circuited by the ErrorResponse.
New delayResponse
function does it right.
Should not break you unless you incorrectly expected no delay for errors.
Also, this library no longer calls RxJS delay()
which may make testing with it easier
(Angular TestBed does not handle RxJS delay()
well because that operator uses interval()
).
Also fixes type error (issue #180).
Can make use of HttpParams
which yields a request.urlWithParams
.
Added supporting HeroService.searchHeroes(term: string)
and test.
No longer modify the request data coming from client. Fixes #164
Support Angular v5.
BREAKING CHANGE: HTTP response data no longer wrapped in object w/ data
property by default.
In this release, the dataEncapsulation
configuration default changed from false
to true
. The HTTP response body holds the data values directly rather than an object that encapsulates those values, {data: ...}
. This is a breaking change that affects almost all existing apps!
Changing the default to false
is a breaking change. Pre-existing apps that did not set this property explicitly will be broken because they expect encapsulation and are probably mapping
the HTTP response results from the data
property like this:
.map(data => data.data as Hero[])
To migrate, simply remove that line everywhere.
If you would rather keep the web api's encapsulation, {data: ...}
, set dataEncapsulation
to true
during configuration as in the following example:
HttpClientInMemoryWebApiModule.forRoot(HeroInMemDataService, { dataEncapsulation: true })
We made this change because
-
Almost everyone seems to hate the encapsulation
-
Encapsulation requires mapping to get the desired data out. With old
Http
that isn't too bad because you needed to map to get data anyway (res => res.json()
). But it is really ugly forHttpClient
because you can't use the type HTTP method type parameter (e.g.,get<entity-type>
) and you have to map out of the data property (.map(data => data.data as Hero[]
). That extra step requires explanations that distract from learningHttpClient
itself. Now you just writehttp.get<Hero[]>()
and you’ve got data (please add error handling). -
While you could have turned off encapsulation with configuration as of v.0.4, to do so took yet another step that you’d have to discover and explain. A big reason for the in-mem web api is to make it easy to introduce and demonstrate HTTP operations in Angular. The out-of-box experience is more important than avoiding a breaking change.
-
The security flaw that prompted encapsulation seems to have been mitigated by all (almost all?) the browsers that can run an Angular (v2+) app. We don’t think it’s needed anymore.
-
A most real world APIs today will not encapsulate; they’ll return the data in the body without extra ceremony.
- improves README
- updates v0.4.0 entry in the CHANGELOG to describe essential additions to SystemJS configuration.
- no important functional changes.
Feature - offer separate HttpClientInMemoryWebApiModule
and HttpInMemoryWebApiModule
.
closes #140
closes #136
A breaking change if you expected genId
to generate ids for a collection
with non-numeric item.id
.
Refactoring for clarity and to correctly reflect intent.
A breaking change only if your customizations depend directly and explicitly on RequestInfo
or the get
, delete
, post
, or put
methods.
-
replace all
switchMap
withconcatMap
because, in all previous uses ofswitchMap
, I really meant to wait for the source observable to complete before beginning the inner observable whereasswitchMap
starts the inner observable right away. -
restored
collection
to theRequestInfo
interface and set it inhandleRequest_
-
get
,delete
,post
, andput
methods get thecollection
fromrequestInfo
; simplifies their signatures to one parameter.
-
Postpones the in-memory database initialization (via
resetDb
) until the first HTTP request. -
Your
createDb
method can be asynchronous. You may return the database object (synchronous), an observable of it, or a promise of it. Issue #113. -
fixed some rare race conditions.
Support PassThru.
The passthru feature was broken by 0.4.0
- add passthru to both
Http
andHttpClient
- test passThru feature with jasmine-ajax mock-ajax plugin to intercept Angular's attempt to call browser's XHR
- update devDependency packages
- update karma.conf with jasmine-ajax plugin
Theme: Support HttpClient
and add tests.
See PR #130.
The 0.4.0 release was a major overhaul of this library.
You don't have to change your existing application code if your app uses this library without customizations.
But this release's breaking changes affect developers who used the customization features or loaded application files with SystemJS.
BREAKING CHANGES: Massive refactoring. Many low-level and customization options have changed. Apps that stuck with defaults should be (mostly) OK.
If you're loading application files with SystemJS (as you would in a plunker), see the instructions below.
- added support for
HttpClient
-> renaming of backend service classes - added tests
- refactor existing code to support tests
- correct bugs and clarify choices as result of test
- add some configuration options
- dataEncapsulation (issue #112, pr#123)
- post409
- put404b
POST commands/resetDb
passes the request to yourresetDb
method so you can optionally reset the database dynamically to arbitrary initial states (issue #128)- when HTTP method interceptor returns null/undefined, continue with service's default processing (pr #120)
- can substitute your own id generator,
geniD
- parseUrl -> parseRequestUrl
- utility methods exposed in
RequestInfo.utils
- reorganize files into src/app and src/in-mem
- adjust gulp tasks accordingly
If you’re loading application files with SystemJS (as you would in a plunker), you’ll have to configure it to load Angular’s umd.js
for HttpModule
and the tslib
package.
To see how, look in the map
section of the
src/systemjs.config.js
for this project for the following two additional lines :
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
...
'tslib': 'npm:tslib/tslib.js',
You've already made these changes if you are using HttpClient
today.
If you’re sticking with the original Angular Http
module, you must make this change anyway! Your app will break as soon as you run npm install
and it installs >=v0.4.0.
If you're using webpack (as CLI devs do), you don't have to worry about this stuff because webpack bundles the dependencies for you.
- Bug fixes PRs #91, 95, 106
- Now runs in node so can use in "universal" demos. See PR #102.
- Support Angular version 4
- Remove reflect-matadata and zone.js as peerDependencies
- Unpin RxJs
- Update to Angular 2.4.0
- Fixed regression in handling commands, introduced in 0.2.0
- Improved README
-
BREAKING CHANGE: The observables returned by the
handleCollections
methods that process requests against the supplied in-mem-db collections are now "cold". That means that requests aren't processed until something subscribes to the observable ... just like real-worldHttp
calls.Previously, these request were "hot" meaning that the operation was performed immediately (e.g., an in-memory collection was updated) and then we returned an
Observable<Response>
. That was a mistake! Fixing that mistake might break your app which is why bumped the minor version number from 1 to 2.We hope very few apps are broken by this change. Most will have subscribed anyway. But any app that called an
http
method with fire-and-forget ... and didn't subscribe ... expecting the database to be updated (for example) will discover that the operation did not happen. -
BREAKING CHANGE:
createErrorResponse
now requires theRequest
object as its first parameter so it can prepare a proper error message. For example, a 404errorResponse.toString()
now shows the request URL. -
Commands remain "hot" — processed immediately — as they should be.
-
The
HTTP GET
interceptor in examplehero-data.service
shows how to create your own "cold" observable. -
While you can still specify the
inMemDbService['responseInterceptor']
to morph the response options, the previously exportedresponseInterceptor
function no longer exists as it served no useful purpose. Added theResponseInterceptor
type to remind you of the signature to implement. -
Allows objects with
id===0
(issue #56) -
The default
parseUrl
method is more flexible, thanks in part to the newconfig.apiBase
property. See the ReadMe to learn more. -
Added
config.post204
andconfig.put204
to control whether PUT and POST return the saved entity. It istrue
by default which means they do not return the entity (status=204
) — the same behavior as before. (issue #74) -
response.url
is set torequest.url
when this service itself creates the response. -
A few new methods (e.g.,
emitResponse
) to assist in HTTP method interceptors.
- Update to Angular 2.2.0.
- Swap
"lib": [ "es2015", "dom" ]
intsconfig.json
for @types/core-jsin
package.json` issue #288
- Update to Angular 2.2.0.
- Add
responseInterceptor
for issue #61
-
Update README for 0.1.11 breaking change: npm publish as
esm
and aumd
bundleGoing to
umd
changes yoursystemjs.config
and the way you import the library.In
systemjs.config.js
you should change the mapping to:'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
then delete from
packages
:'angular-in-memory-web-api': { main: './index.js', defaultExtension: 'js' }
You must ES import the in-mem module (typically in
AppModule
) like this:import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
- exclude travis.yml and rollup.config.js from npm package
- BREAKING CHANGE: npm publish as
esm
and aumd
bundle. Does not change the API but does change the way you register and import the in-mem module. Documented in later release, v.0.1.13
- Catch a
handleRequest
error and return as a failed server response.
- Restore delay option, issue #53.
- Angular 2.1.x support.
- Do not add delay to observable if delay value === 0 (issue #47)
- Can override
parseUrl
method in your db service class (issue #46, #35) - README.md explains
parseUrl
override. - Exports functions helpful for custom HTTP Method Interceptors
createErrorResponse
createObservableResponse
setStatusText
- Added
examples/hero-data.service.ts
to show overrides (issue #44)
- project.json license changed again to match angular.io package.json
- project.json license is "MIT"
- Fix typos
- AoT support from Tor PR #36
- Update npm packages
parseId
fix from PR #33
- Exclude src folder and its TS files from npm package
- Renamed package to "angular-in-memory-web-api"
- Added "passThruUnknownUrl" options
- Simplified
forRoot
and made it acceptable to AoT - Support case sensitive search (PR #16)
The last npm package named "angular2-in-memory-web-api" was v.0.0.21
- Add source maps (PR #14)
- Angular 2.0.0
- Typescript 2.0.2
- RC7
- RC6 (doesn't work with older versions)
- fix
forRoot
type constraint - clarify
forRoot
param
- No longer exports
HttpModule
- Can specify configuration options in 2nd param of
forRoot
- jsDocs for
forRoot
- RC5
- Support for NgModules
- RC4
- RC3
- RC2
- add RegExp query support
- find-by-id is sensitive to string ids that look like numbers
- added "main:index.js" to package.json
- updated to typings v.1.0.4 (a breaking release)
- dependencies -> peerDependencies|devDependencies
- no es6-shim dependency.
- use core-js as devDependency.
- renamed the barrel core.js -> index.js
- systemjs -> commonjs
- replace es6-shim typings w/ core-js typings
- RC1
- update to 2.0.0-rc.1
- RC0
- update to 2.0.0-rc.0
- PROVISIONAL - refers to @angular packages
- update to 0.0.0-5
- PROVISIONAL - refers to @angular packages
- update to 0.0.0-3
- rxjs: "5.0.0-beta.6"
- PROVISIONAL - refers to @angular packages
- update to 0.0.0-2
- PROVISIONAL - refers to @angular packages
- DO NOT USE. Not adapted to new package system.
- Initial cut for Angular 2 repackaged
- target forthcoming Angular 2 RC