# microback

> Create simple api server using koa, mongoose, webpack for REST and Websocket

Latest version **0.2.4** (published 2017-11-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install microback
pnpm add microback
yarn add microback
bun add microback
```

Provides the commands `dev`, `build`, `microback`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2017-11-06 |
| First published | 2017-09-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 23 |
| Known vulnerabilities | 0 (+11 in 3 direct dependencies) |
| Install scripts | no |
| Author | Sirajul |
| Maintainers | sir4ju1 |

## Links

- npm: https://www.npmjs.com/package/microback
- npm.io page: https://npm.io/package/microback

## Dependencies (23)

- [koa](https://npm.io/package/koa.md) ^2.3.0
- [chalk](https://npm.io/package/chalk.md) ^2.1.0
- [kcors](https://npm.io/package/kcors.md) ^2.2.1
- [ramda](https://npm.io/package/ramda.md) ^0.24.1
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [koa-jwt](https://npm.io/package/koa-jwt.md) ^3.2.2
- [nodemon](https://npm.io/package/nodemon.md) ^1.12.0
- [webpack](https://npm.io/package/webpack.md) ^3.5.6
- [koa-body](https://npm.io/package/koa-body.md) ^2.3.0
- [mongoose](https://npm.io/package/mongoose.md) ^4.11.11
- [pluralize](https://npm.io/package/pluralize.md) ^7.0.0
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.0
- [koa-router](https://npm.io/package/koa-router.md) ^7.2.1
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^5.1.0
- [babel-loader](https://npm.io/package/babel-loader.md) ^7.1.2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.0.0
- [koa-websocket](https://npm.io/package/koa-websocket.md) ^4.0.0
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.6.0
- [mongoose-paginate](https://npm.io/package/mongoose-paginate.md) ^5.0.3
- [webpack-node-externals](https://npm.io/package/webpack-node-externals.md) ^1.6.0
- [babel-plugin-module-resolver](https://npm.io/package/babel-plugin-module-resolver.md) ^2.7.1
- [friendly-errors-webpack-plugin](https://npm.io/package/friendly-errors-webpack-plugin.md) ^1.6.1
- [babel-plugin-transform-decorators-legacy](https://npm.io/package/babel-plugin-transform-decorators-legacy.md) ^1.3.4

## Recent versions

- 0.2.4 (latest) — 2017-11-06
- 0.2.3 — 2017-11-06
- 0.2.2 — 2017-11-06
- 0.2.1 — 2017-11-06
- 0.2.0 — 2017-10-31
- 0.1.6 — 2017-10-18
- 0.1.5 — 2017-09-22
- 0.1.4 — 2017-09-20
- 0.1.3 — 2017-09-19
- 0.1.2 — 2017-09-19
- 0.1.1 — 2017-09-19
- 0.1.0 — 2017-09-19
- 0.0.6 — 2017-09-19
- 0.0.5 — 2017-09-19
- 0.0.4 — 2017-09-19
- … 3 more at https://npm.io/package/microback/versions

## README

# Microback
### An API microservice server using koa. It can be used to build both REST API and Websocket server.

### For starter application please look at: [microback-starter](https://github.com/sir4ju1/microback-starter)

## Documentation
### To start from scratch
 1. ```yarn add microback```
 2. add .env file 
 3. add following key
    ``` 
        PORT=2020
        MONGODB=mongodb://localhost:27017/yourdb
        SECUREKEY=my-key
    ```
  4. add `app` folder
  5. add `api` inside `app` folder
  6. create your first REST API controller which in this case `UserRest`
      ``` javascript
        /** 
          * import all necessary function from microback
          * RestGen is responsible to create automatic route
          * route is decorator funciton
          * auth is used for hashing some string e.g. password
          */ 
        import { RestGen, route, auth } from 'microback'
        import User from 'model/user'
        class UserRest extends RestGen {
          /**
            * construction is used to pass the name
            * of the endpoint which will be automatically pluralized
            * for certain endpoints which can be checked from
            * http://yourhost/routes
            * second argument is for model object if you need to create
            * automatic RESt routes for a certain model and this is optional
            */
          constructor () {
            super('user', User)
          }
          /**
            * creating route with method and path
            * using decorator pattern and write 
            * function using async await
            */
          @route('post', 'login')
          async login (ctx) {
            try {
              let body = ctx.request.body
              body.password = auth.generateHash(body.password)
              const token = await auth.login(body.email, body.password, User)
              ctx.body = { success: true, token }
            } catch (error) {
              ctx.body = { success: false, error }
            }
          }
        }
        export default UserRest
      ```

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