Skip to content

bcooksey/premiere

Repository files navigation

Premiere

npm version Build Status Code Climate Test Coverage

Javascript ORM for consuming Restful APIs.

Premiere is standalone (independent of framework), so you can use it with your favorite library/framework, be it MobX React, Angular, VueJS, jQuery, Redux. You name it!

We recommend the use with TypeScript or ECMAScript 6 (ES6).

Website

For a better experience, please checkout the Website

Workflow

Workflow

** For more about how promises work, check out Dave Atchley's article

Features

  • 100% Unit Tested
  • Normalization
  • Smart Caching
  • Support to Foreign keys
  • HTTP Header support (frequently used with Authorization and CSRF token)

Installation

Using npm:

$ npm install premiere --save

Using cdn:

<script src="https://unpkg.com/premiere/dist/premiere.min.js"></script>

Note: You'll need a ES6 polyfill on your build pipeline.

Setup

This code is written in TypeScript.

import {Api, api, Model} from 'premiere';

Api.base = 'http://rest.learncode.academy/api/YOUR_NAME_HERE/';

/*
 * Using API directly
 */

api.http().get('albums'); // GET http://rest.learncode.academy/api/YOUR_NAME_HERE/albums
api.http().post('albums'); // POST http://rest.learncode.academy/api/YOUR_NAME_HERE/albums

/*
 * Using Models
 */

class Album extends Model {
    static path = 'albums';
    
    id: number;
    name: string;
}

Album.all(); // GET http://rest.learncode.academy/api/YOUR_NAME_HERE/albums
Album.find(1); // GET http://rest.learncode.academy/api/YOUR_NAME_HERE/albums/1
Album.save({name: 'new album'});// POST http://rest.learncode.academy/api/YOUR_NAME_HERE/albums

Tutorials

The tutorials are written in TypeScript.

Documentation

Check out the full Documentation.

Examples

Projects

Dependencies

  • axios for handling HTTP Requests.

Resources

Articles

Motivation

Premiere is inspired by Laravel (Eloquent) and Rails (Active Record).

Because of frameworks like these, building Restful APIs is a much smoother path.

The goal of Premiere is to provide the same facility and power that these libraries provide, just this time on the client side.

License

MIT