# rest-api-controller

> API Wrapper Module for a JS/TS client

Latest version **1.4.7** (published 2021-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rest-api-controller
pnpm add rest-api-controller
yarn add rest-api-controller
bun add rest-api-controller
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.7 |
| Published | 2021-12-16 |
| First published | 2020-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | Digital Masterpieces |
| Maintainers | digitalmasterpieces-admin |

## Links

- npm: https://www.npmjs.com/package/rest-api-controller
- Repository: https://bitbucket.org/digitalmasterpieces/stylization-sdk
- Homepage: https://bitbucket.org/digitalmasterpieces/stylization-sdk#readme
- Issues: https://bitbucket.org/digitalmasterpieces/stylization-sdk/issues
- npm.io page: https://npm.io/package/rest-api-controller

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Recent versions

- 1.4.7 (latest) — 2021-12-16
- 1.4.6 — 2021-10-28
- 1.4.5 — 2021-05-27
- 1.4.4 — 2021-04-20
- 1.4.3 — 2021-04-20
- 1.4.2 — 2021-01-22
- 1.4.1 — 2021-01-20
- 1.4.0 — 2021-01-20
- 1.3.0 — 2020-11-16
- 1.2.3 — 2020-11-10
- 1.2.2 — 2020-11-10
- 1.2.1 — 2020-11-10
- 1.2.0 — 2020-10-12
- 1.1.0 — 2020-09-29
- 1.0.0 — 2020-09-22

## README

# REST API Controller

[![npm](https://img.shields.io/npm/v/rest-api-controller)](https://www.npmjs.com/package/rest-api-controller)
![npm bundle size](https://img.shields.io/bundlephobia/min/rest-api-controller)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

Generic REST API wrapper for connecting any client API to a HTTP request handling library.

## Installing

You can install REST API Controller using NPM to get the latest version of our library.

> `npm install rest-api-controller`

## Usage

Once installed, create your own client by using the API controller.

```ts
import ApiController from "rest-api-controller";

const API_URL = "https://my-example-api.com/v1";

const ROUTES = {
    users: "/users/:id",
    cats: "/users/:id/cats",
    dogs: "/users/:id/dogs"
};

type RouteKey = keyof typeof ROUTES;

class ExampleClient {
    private controller: ApiController<RouteKey>;

    constructor() {
        this.controller = new ApiController(API_URL, ROUTES);
    }

    public async getUsers() {
        return this.controller.get<User[]>("users");
    }

    public async getUserCats(userId: string) {
        return this.controller.get<Cats[]>("cats", { id: userId });
    }

    public async createUserDog(userId: string) {
        const data = {
            name: "Rex",
            age: 3,
            color: "black"
        };

        return this.controller.post<Dog>("dogs", { id: userId }, data);
    }
}
```

## License

[MIT](LICENSE)

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