2.4.3 • Published 3 years ago

ag-mock-server v2.4.3

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

AgMockServer

Mock Backend & GUI for your swagger(in json format).

How to use articles : Medium || Hashnode;

Try the Demo App - AgMockServerDemo

Build Status

Features

  • Ability to send pre-configured responses for a specific API.
  • An editable light GUI for mockserver.
  • State consistency - even when page refreshes.
  • Ability to UPLOAD & DOWNLOAD json file - to retain previous state.
  • Configurable accross different environments.
  • ✨See the Magic after clicking the menu button ✨

    The main goal of AGMockServer is to ease development effort of a UI Developer :)

Installation

AgMockServer requires Node.js v10+ to run.

npm install ag-mock-server

2-ways to use it :

1. For Angular Apps

AgMockServer is basically an Inteceptor(Angular) which acts a fake bakend:

Image - Flow diagram of Ag Mock Interceptor as Fake Bakend.

How to use for Angular:

For Angular 9 or more

  1. Add the following Services & Interfaces in the providers section of AppModule. That's all dude.. Enjoyy!!
...
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

import { environment } from 'src/environments/environment';
import { ByPassInterceptor, FakeBackendService } from 'ag-mock-server';

@NgModule({
  ***
  providers: [
    ...(
      environment.production ? // <--can use any flag other than PROD flag.
        [] : [
          {
            provide: HTTP_INTERCEPTORS,
            useClass: ByPassInterceptor,
            multi: true,
          },
          {
            provide: APP_INITIALIZER,
            useFactory: (service: FakeBackendService) => () => { return service.startMockServer(); },
            deps: [FakeBackendService],
            multi: true,
          }
        ]
    ),
  ],
})
export class AppModule { }

For Angular 8 or less - 2 steps (Or 🤔 if the above approach gives you errors use this one).

  1. Add the following services, interfaces in the providers section & importing "AgMockServerModule" as show below in AppModule.
...
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { environment } from 'src/environments/environment';
import { ByPassInterceptor, AgMockServerModule } from 'ag-mock-server';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule, // <-- Import if not already imported for animations
    AgMockServerModule, // <-- Import this module
  ],
  providers: [
    ...(
      environment.production ? // <--can use any flag other than PROD flag.
        [] : [
          {
            provide: HTTP_INTERCEPTORS,
            useClass: ByPassInterceptor,
            multi: true,
          },
        ]
    ),
  ],
  bootstrap: [AppComponent],
})
export class AppModule { }
  1. Inject "FakeBackendService" in the AppComponent and start the mockServer.
...
import { environment } from 'src/environments/environment';
import { FakeBackendService } from 'ag-mock-server';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  constructor(private _fakeBackend: FakeBackendService) {
    if(!environment.production) {
      this._fakeBackend.startMockServer(); //<-- Actually starts the mock server here..
    }
  }

...
}

2. For All Other Web Apps.

AgMockServer is basically mockserver running on port xxxx with configrable apis from json:

Image - Flow diagram of Ag Mock Interceptor as Fake Bakend.

How to use for all other web pages:

  • Developement still in progress - expected release in version 3.0.

Development

Have suggestions or found bugs in the app? Great. Please share your feedback in the below articles: Medium || Hashnode || Connect on linkedin;

License

MIT

Free Software, Hell Yeah!

2.4.1

3 years ago

2.4.0

3 years ago

2.4.3

3 years ago

2.4.2

3 years ago

2.3.0

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.4

3 years ago

2.2.5

3 years ago

2.3.3

3 years ago

2.2.4

3 years ago

2.2.7

3 years ago

2.2.6

3 years ago

2.2.9

3 years ago

2.2.8

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.4

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.7

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.3

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago