npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ag-mock-server

v2.4.3

Published

### How to use articles : [Medium](https://medium.com/@akshaynetha1015/agmockserver-how-to-use-angular-mock-server-fake-backend-a2ac1570b246) || [Hashnode](https://hashnode.com/draft/60f97b5962e20b58c1c8f9b5);

Downloads

63

Readme

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!