A mock HTTP server for angular2 that runs in the browser. Front-end dev when the backend is missing.
MIT License
An angular2+ mock XHRBackend to ease front-end development when no real back-end is available.
npm install ng2-mock-server [--save | --save-dev]
In your main module file (other mandatory parts like Component-declarations omitted):
import { MockRouteInitializer } from './mock-route-initializer';
import { NgModule } from '@angular/core';
import { MockServerModule, RouteInitializer } from 'ng2-mock-server';
import { HttpModule } from '@angular/http';
@NgModule({
imports: [
HttpModule,
MockServerModule
],
providers: [
{ provide: RouteInitializer, useClass: MockRouteInitializer }
]
})
export class AppModule {
}
MockRouteInitializer is where you define your mock-routes:
import { RouteInitializer, MockSrvRouter, json, res } from 'ng2-mock-server';
import { ResponseOptions } from '@angular/http';
export class MockRouteInitializer implements RouteInitializer {
initialize(r: MockSrvRouter): void {
r.get("/hello", (req : Request, ...params : string) {
return res(200, "world");
});
r.get("/hello/:name", (req : Request, name : string) {
return res(200, name);
});
}
}
For development and running the example project, clone this repo, make the desired changes and:
# 1. build and link the module:
./buildAndLink.sh
# 2. use the linked module and start the example:
cd example
npm link ng2-mock-server
npm start
You can also use buildAndRunExample.sh to do all those steps at once
onComplete
callbacks weren't called after a request.router.setup(r => {...})
the default way of setting up the routes to eliminate the call to r.ready()
. This is backwards-compatible so if you're not using router.setup()
and call router.ready()
, everything will work just fine.Initial release.
Please create issues with bug reports, feature requests or asking for help.
Pull requests more than welcome.
Released under the MIT Licence.