1.0.0-beta.2.2.1 • Published 9 years ago

@megawubs/avid v1.0.0-beta.2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

Avid

API consumption on fire, inspired by Laravel's Eloquent

Installation

For now, this module only works inside a laravel installation.

$ yarn install @megawubs/avid

Usage

This wrapper expects a certain api design. The name of the model you create is automatically mapped to an api endpoint. Let's say we have a User model, by default Avid will generate a resource uri of /api/v1/user, expecting an json array of all user objects

A Avid model is defined like this:

import {Avid} from "@megawubs/avid"

export class User extends Avid{
    get _version(){
        return 'v1'
    }
    
    get _name(){
        return 'user'
    }
    
    posts(){
        return this.hasMany(Post, 'posts');
    }
}

export class Post extends Avid{
    get _version(){
        return 'v1'
    }
    
    get _name(){
        return 'post'
    }

    user(){
        return this.belongsTo(User);
    }
}

User.find(1) //model fetched from api
.then(user => user.posts) //fetch relations from api
.then(posts => console.log(posts)); //log relations

Post.find(1) //model fetched from api
.then(post => post.user) //fetch relation from api
.then(post => console.log(post)); //log relation

 let user = new User(); //new up a user

user.name = 'John'
user.email = 'do@john.com'
user.email = 'secret'
 user.save()
 .then(user => console.log(user.id)); //1 (saved user through the API)

 User.find(1).then(user => {
 user.name = 'jane'
 user.email = 'do@jane.com'
 return user.save();
 }).then(updatedUser => console.log(updatedUser.name)); //jane

Testing

To run the tests you need to have docker and docker-compose installed. When you have both run docker-compose up in the project root and navigate your browser to http://localhost:8001 to run and see the tests

1.0.0-beta.2.2.1

9 years ago

1.0.0-beta.2.2

9 years ago

1.0.0-beta.2.1

9 years ago

1.0.0-beta.2

9 years ago

1.0.0-beta.1

9 years ago

0.0.41

9 years ago

0.0.40

9 years ago

0.0.38

9 years ago

0.0.37

9 years ago

0.0.36

9 years ago

0.0.35

9 years ago

0.0.30

9 years ago

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago