在 Angular 中简洁优雅的生成 mock API

1,150 阅读1分钟

ng-mocker

10 seconds to build virtual interfaces in angular.

Enjoy

My sister was still in primary school, but it took her only 1 minutes to learn how to use it. It's too simple.

  1. import:

install: npm i --save ng-mocker

// in app.module.ts
import { MockerModule } from 'ng-mocker'

// ...
imports: [
  HttpClientModule,
  MockerModule.forRoot(Mocks),
],
  1. create your api:
export class Mocks {

  host: string = 'http://github.com'

  '/users/options'(req): any {
    return { message: 'ok!' }
  }
}

when you request /users/options with angular, { message: 'ok!' } will be returned.

LICENSE

MIT