# @swkng/httpmock

> 此版為 [Angular CLI](https://github.com/angular/angular-cli) version 15.0.0 的 Http Mock

Latest version **15.0.1125** (published 2023-02-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @swkng/httpmock
pnpm add @swkng/httpmock
yarn add @swkng/httpmock
bun add @swkng/httpmock
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 15.0.1125 |
| Published | 2023-02-12 |
| First published | 2021-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 115.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lawrence8358@hotmail.com |
| Maintainers | lawrence8358 |

## Links

- npm: https://www.npmjs.com/package/@swkng/httpmock
- npm.io page: https://npm.io/package/@swkng/httpmock

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 15.0.1125 (latest) — 2023-02-12
- 1.0.1124 — 2023-02-12
- 1.0.1123 — 2023-02-12
- 1.0.1 — 2022-01-28
- 1.0.0 — 2021-08-27

## README

# HttpMock

此版為 [Angular CLI](https://github.com/angular/angular-cli) version 15.0.0 的 Http Mock

## 如何使用
+ 宣告 Mock Controller `mock.controller.ts`
  ``` typescript
  import { SwkHttpMockRequest } from '@swk';

  class MockApiController {
    static GetInfo() {
      return {
        name: 'lawrence',
        tel: '0900000000',
        exp: new Date().getTime()
      };
    }
  }

  export const MockApiRouter = {
    'GET /api/Info': (req: SwkHttpMockRequest) => MockApiController.GetInfo()
  };
  ```
  
+ 在 `app.module.ts` 中 import
  ``` typescript
  // Http Mock
  import { SwkHttpMockModule } from '@swk';
  import * as MOCKDATA from './mock.controller';
  import { HttpClientModule } from '@angular/common/http';
  const MOCKMODULES = [];
  MOCKMODULES.push(SwkHttpMockModule.forRoot({
    data: MOCKDATA,
    log: true,
    delay: 300
  }));

  @NgModule({
    declarations: [
      AppComponent
    ],
    imports: [
      BrowserModule,
      AppRoutingModule,
	  HttpClientModule, //<-- 加入此項目
      ...MOCKMODULES //<-- 加入此項目
    ],
    providers: [],
    bootstrap: [AppComponent]
  })
  export class AppModule { }
  ```

+ Http 呼叫，使用原本方法即可，無須改變任何程式
  ``` typescript
  @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.less']
  })
  export class AppComponent { 
    constructor(private http: HttpClient) { }

    onHttpMock() {
      this.http.get('/api/Info').subscribe(result => this.mockResult = result);
    }
  }
  ```

---
_Source: https://npm.io/package/@swkng/httpmock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
