# ngx-endpoint-module

> Angular version: 11.2.7

Latest version **0.1.0-beta-1** (published 2022-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-endpoint-module
pnpm add ngx-endpoint-module
yarn add ngx-endpoint-module
bun add ngx-endpoint-module
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-beta-1 |
| Published | 2022-03-09 |
| First published | 2022-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 131.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Marian Vismek |
| Maintainers | marian.vismek |
| Keywords | angular, endpoint, http, typescript |

## Links

- npm: https://www.npmjs.com/package/ngx-endpoint-module
- Repository: https://github.com/majky14/endpoint-module
- Issues: https://github.com/majky14/endpoint-module/issues
- npm.io page: https://npm.io/package/ngx-endpoint-module

## Dependencies (1)

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.0-beta-1 (latest) — 2022-03-09
- 0.1.0-beta-2 (beta) — 2022-03-16

## README

# EndpointModule

Angular version: 11.2.7

This library provides simplicity for using endpoints.

## Basic usage

Import `EndpointModule` in your `AppModule` and setup config in providers.

    providers: [
        {provide: EndpointConfigToken, useValue: {baseUrl: 'https://api.mocki.io/v1/469a9425'}}
    ]

Now you can decorate some property with `@EndpointDecorator` and create an endpoint.

    export class AppComponent implements OnInit {
      @EndpointDecorator('users')
      public users: Endpoint;
    }

If you now call `this.users.list().subscribe()` within `AppComponent` you will perform GET request to `https://api.mocki.io/v1/469a9425/users`.

We can also create an endpoint by `@EntityDecorator`. Simply create class which represent entity, extend the class with `Entity` and decorate with `@EntityDecorator`.

    @EntityDecorator('users')
    export class User extends Entity {
      name: string;
      roles?: {
        [key: string]: boolean;
      };
    } 

Now you can call `User.list().subscribe()` and you will see the same request as above.

Next, we can create an endpoint in a config. This approach allow us to create custom endpoint methods.
For example, we want a request to `/users/profile` we can create custom endpoint class and define such method.

    export class UserEndpoint extends Endpoint<User> {
      public profile(): Observable<User> {
        return this.http.get(`${this.endpoint}/profile`) as Observable<User>;
      }
    }
    
For this we have to include this endpoint in a config

    providers: [
        {
            provide: EndpointConfigToken,
            useValue: {
                baseUrl: 'https://api.mocki.io/v1/469a9425',
                endpoints: [
                    {endpointName: 'users', endpoint: UserEndpoint}
                ]
            }
        }
    ] 

Now we can retype endpoint class in `AppComponent` to new created `UserEndpoint` and call custom method.

    export class AppComponent implements OnInit {
      @EndpointDecorator('users')
      public users: UserEndpoint;
    }
    
If you now call `this.users.profile().subscribe()` within `AppComponent` you will perform GET request to `https://api.mocki.io/v1/469a9425/users/profile`.

### Base endpoint methods

| Method | Arguments | Api method | Returns |
| --- | --- | --- | --- |
| list | none | GET | Observable\<T[]> |
| create | body: Partial\<T> | POST | Observable\<T> |
| update | id: string, body: Partial\<T> | PATCH | Observable\<T> |
| read | id: string | GET | Observable\<T> |
| delete | id: string | DELETE | Observable\<T> |

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