A Hydra Core aware API client
JavaScript
Latest commit 65c8ce1 Jun 8, 2016 @Dani723 Dani723 Version 0.5.3
Permalink
Failed to load latest commit information.
dist
lib
tests
.editorconfig
.gitignore
.jscsrc
.jshintrc
.npmignore
.travis.yml
LICENSE
README.md
jspm.browser.js
jspm.config.js
jspm.node.js
package.json
testem.json

README.md

hyjax

Build Status

A Hydra Core aware API client based on pajax.

Installation

jspm install github:pajax/hyjax

Usage

See pajax for further information.

import Hyjax from 'hyjax';

let apiDoc = new Hyjax.ApiDocumentation('http://www.your-app.url');
let promise = apiDoc.load();

let hyjax = new Hyjax({
  apiDoc // optional
);

// Will resolve after api doc is loaded
hyjax.get('/iri').then(...)

ApiDoc

TODO

Basic resource model

hyjax.get('/foo')
     .then(res=>res.jsonld())
     .then(foo=>{
        foo;                       // jsonld object
        foo.data;                  // the resource's data
        foo.id;                    // alias for foo.data['@id']
        foo.types;                 // array with type iris
        foo.isTypeOf(type);        // Checks if resource of specified type
        foo.getByIRI(iri);         // returns the iris value
        foo.metaForProperty(prop); // meta information for property
        foo.metaForIRI(iri);       // meta information for iri
     });

Custom resource model

class Foo extends Hyjax.Resource {
  get isFoo() {
    return true;
  }
});

hyjax.get('/foo')
     .then(res=>res.jsonld(Foo)) // Use Foo model
     .then(foo=>{
        foo.isFoo; // true
     });

Collection resource model

hyjax.get('/addresses/')
     .fetch()
     .then(res=>res.jsonld(Hyjax.PagedCollection)) // Or Hyjax.Collection
     .then(addresses=>{
       addresses;       // The resource
       addresses.items; // Reference to collection member
     });

Type mixins

Hyjax.Resource.mixin('/classes/Foo', {
  get hasMixin() {
    return true;
  }
});

hyjax.get('/foo')
     .then(res=>res.jsonld())
     .then(foo=>{
        foo.hasMixin; // true
     });

Deeploading

Allows deeploading of @ids

hyjax.get('/user/foo')
     .then(res=>res.jsonld())
     .then(user=>{
       return hyjax.deepload(user, {
         comments: true,
         image: {
           force: true,             // Load even if it's not an @id
           body: res=> res.blob()   // Resolve as blob instead of jsonld
         },
         address: {
           model: Address           // Use specified resource model
           as: 'userAddress',       // Store as userAddress
           deepload: {              // Define sub deeploads
             country: true
           }
         }
       })
     })
     .then(user)=>{
       // user.comments[]          // comments models
       // user.image               // blob
       // user.userAddress         // address model
       // user.userAddress.country // country model
     });