2.0.1 • Published 4 years ago

modele v2.0.1

Weekly downloads
51
License
MIT
Repository
github
Last release
4 years ago

Introduction

Modele helps you to build requests for REST API. Organize the requests into classes that represents your Back-end models.

This library takes care of this things, helping the developer to keep the communication-to-server logic, sorted by models, providing:

  • Built-in Rest API methods like get, create, update and delete.
  • Mutation of the data, before it is sent to the server.
  • Validation of data on the client side, including some built-in rules.

Examples

Documentation

Installation

Using NPM:

npm i --save modele

Using yarn:

yarn add modele

Basic Usage

Setup Rest API, validation and mutations:

import axios from 'axios'
import { Modele } from 'modele'
import { presence } from 'modele/validations'

class User extends Modele {
  // 1. Setup resource baseURL
  static setup () {
    return {
      baseURL: 'https://my-api.com/:api/users[/:id]'
    }
  }

  // 2. Setup request engine
  static request (config) {
    return axios(config)
  }

  // 3. Setup mutator functions per property
  static mutations () {
    return {
      name: (value) => value && value.trim()
    }
  }

  // 4. Setup validation rules per property
  static validation () {
    return {
      name: [presence()],
      surname: [presence()]
    }
  }
}

Usage:

const user = new User({ name: 'Darth   ', surname: 'Vader' })
// => User { name: 'Darth   ', surname: 'Vader' }

user.$validate()
// => true

User.create(user, { api: 1 })
// => POST https://my-api.com/1/users { name: 'Darth', surname: 'Vader' }

Read the Wiki to learn more.

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

License

MIT

Copyright (c) 2017-present, Alexandre Magro

2.0.1

4 years ago

2.0.0

4 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.1.0

7 years ago