All Projects β†’ reyesoft β†’ Ts Angular Jsonapi

reyesoft / Ts Angular Jsonapi

Licence: mit
JsonApi library for AngularJS + Typescript πŸ‘Œ

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ts Angular Jsonapi

Placementmnit
Official Placement Portal : MNIT Jaipur
Stars: ✭ 29 (-25.64%)
Mutual labels:  angularjs
Smart Kyc
An opensource KYC web application
Stars: ✭ 34 (-12.82%)
Mutual labels:  angularjs
Samay
Command line Time tracking and reporting. Built using Go(programming language) and protocol buffers.
Stars: ✭ 37 (-5.13%)
Mutual labels:  angularjs
Microzz.github.io
πŸ’»https://microzz.com ITζŠ€ζœ―εˆ†δΊ«
Stars: ✭ 29 (-25.64%)
Mutual labels:  angularjs
Advanced Directives With Angular Js
Advanced Directives with Angular JS - Code for the Screencast
Stars: ✭ 33 (-15.38%)
Mutual labels:  angularjs
Tested
Angular Material in MEAN Stack Website Source
Stars: ✭ 35 (-10.26%)
Mutual labels:  angularjs
Angular Auto Complete
AngularJS auto complete plugin
Stars: ✭ 27 (-30.77%)
Mutual labels:  angularjs
Ng1bs4
AngularJS with Bootstrap 4
Stars: ✭ 39 (+0%)
Mutual labels:  angularjs
Todolist
πŸ“„ Task management web application built with AngularJS and Java EE.
Stars: ✭ 33 (-15.38%)
Mutual labels:  angularjs
Soqlbuilder
Node.js and AngularJs based Query Builder for Salesforce using OAuth2 and REST API
Stars: ✭ 37 (-5.13%)
Mutual labels:  angularjs
Angular Gridster2
Angular gridster 2
Stars: ✭ 956 (+2351.28%)
Mutual labels:  angularjs
Generator Angular Auto Admin Loopback
Generator for automatic CRUD angular backend for loopback apps and apis
Stars: ✭ 32 (-17.95%)
Mutual labels:  angularjs
Angular Drag Scroll
Lightweight drag to scroll directive for AngularJS
Stars: ✭ 35 (-10.26%)
Mutual labels:  angularjs
Web Framework For Java
A seed project with spring boot for AngularJS, AngularJs Material, Thymeleaf, RESTful API, MySQL and admin panel based on AdminLTE.
Stars: ✭ 29 (-25.64%)
Mutual labels:  angularjs
Onthefly
πŸ”— Generate TinySVG, HTML and CSS on the fly
Stars: ✭ 37 (-5.13%)
Mutual labels:  angularjs
Duckietv
A web application built with AngularJS to track your favorite tv-shows with semi-automagic torrent integration
Stars: ✭ 942 (+2315.38%)
Mutual labels:  angularjs
Argo
JSON API (jsonapi.org) implementation for Clojure
Stars: ✭ 34 (-12.82%)
Mutual labels:  jsonapi
Depli
A handsome JVM monitoring dashboard
Stars: ✭ 39 (+0%)
Mutual labels:  angularjs
Trycode
Open-source realtime collaborative code editor on Babel, NodeJS, AngularJS, Socket.io, ACE - http://trycode.pw
Stars: ✭ 38 (-2.56%)
Mutual labels:  angularjs
Protokit
πŸ“± A prototype kit for Ionic Framework
Stars: ✭ 36 (-7.69%)
Mutual labels:  angularjs

For the latest Angular, use ngx-jsonapi πŸš€

We are ready for Angular 2 or above versions on ngx-jsonapi.

ts-angular-jsonapi

JsonApi client library for AngularJS + Typescript.

Online demo

You can test library on this online example πŸ‘Œ http://reyesoft.github.io/ts-angular-jsonapi/

Data is obtained from Json Api Playground.

Supported features

  • Cache (on memory): Before a HTTP request objects are setted with cached data.
  • Cache (on memory): TTL for collections and resources
  • Cache on localstorage
  • Pagination
  • Filtering by attributes through a string or a regular expression
  • TS Definitions for strong typing and autocomplete (See example image)
  • Include param support (also, when you save)
  • Two+ equal resource request, only one HTTP call.
  • Equal requests, return a same ResourceObject on memory
  • Default values for a new resource
  • Properties on collections like $length, $is_loading or $source (empty |cache|server)

Usage

More information on examples section.

Installation

First of all, you need read, read and read Jsonapi specification.

npm install ts-angular-jsonapi --save

Dependecies and customization

  1. Add Jsonapi dependency.
  2. Configure your url and other paramemeters.
  3. Inject JsonapiCore somewhere before you extend any class from Jsonapi.Resource.
import 'ts-angular-jsonapi';

var app = angular.module('yourAppName', ['rsJsonapi']);

app.config(['rsJsonapiConfig', (rsJsonapiConfig) => {
  angular.extend(rsJsonapiConfig, {
    url: '//jsonapiplayground.reyesoft.com/v2/'
  });
}]);

var MyController = function(JsonapiCore) {
  // ...
}
MyController.$inject = ['JsonapiCore'];

Examples

Like you know, the better way is with examples. Based on endpoints example library.

Defining a resource

authors.service.ts

class AuthorsService extends Jsonapi.Resource {
  type = 'authors';
  public schema: Jsonapi.ISchema = {
    attributes: {
      name: { presence: true, length: { maximum: 96 } },
      date_of_birth: {},
      date_of_death: {},
      created_at: {},
      updated_at: {}
    },
    relationships: {
      books: {},
      photos: {}
    }
  };
}
angular.module('demoApp').service('AuthorsService', AuthorsService);

Get a collection of resources

Controller

class AuthorsController {
  public authors: any = null;

  /** @ngInject */
  constructor(AuthorsService) {
    this.authors = AuthorsService.all();
  }
}

View for this controller

<p ng-repeat="author in vm.authors">
  id: {{ author.id }} <br />
  name: {{ author.attributes.name }} <br />
  birth date: {{ author.attributes.date_of_birth | date }}
</p>

More options? Collection filtering

Filter resources with attribute: value values. Filters are used as 'exact match' (only resources with attribute value same as value are returned). value can also be an array, then only objects with same attribute value as one of values array elements are returned.

let authors = AuthorsService.all(
  {
    localfilter: { name: 'xx' },            // request all data and next filter locally
    remotefilter: { country: 'Argentina' }  // request data with filter url parameter
  }
);

Get a single resource

From this point, you only see important code for this library. For a full example, clone and see demo directory.

let author = AuthorsService.get('some_author_id');

More options? Include resources when you fetch data (or save!)

let author = AuthorsService.get(
  'some_author_id',
  { include: ['books', 'photos'] },
  success => {
    console.log('Author loaded.', success);
  },
  error => {
    console.log('Author don`t loaded. Error.', error);
  }
);

TIP: these parameters work with all() and save() methods too.

Add a new resource

let author = this.AuthorsService.new();
author.attributes.name = 'Pablo Reyes';
author.attributes.date_of_birth = '2030-12-10';
author.save();

Need you more control and options?

let author = this.AuthorsService.new();
author.attributes.name = 'Pablo Reyes';
author.attributes.date_of_birth = '2030-12-10';

// some_book is an another resource like author
let some_book = this.BooksService.get(1);
author.addRelationship(some_book);

// some_publisher is a polymorphic resource named company on this case
let some_publisher = this.PublishersService.get(1);
author.addRelationship(some_publisher, 'company');

// wow, now we need detach a relationship
author.removeRelationship('books', 'book_id');

// this library can send include information to server, for atomicity
author.save( { include: ['book'] });

// mmmm, if I need get related resources? For example, books related with author 1
let relatedbooks = BooksService.all( { beforepath: 'authors/1' } );

// you need get a cached object? you can force ttl on get
let author = AuthorsService.get(
  'some_author_id',
  { ttl: 60 } // ttl on seconds (default: 0)
);

Update a resource

let author = AuthorsService.get('some_author_id');
this.author.attributes.name += 'New Name';
this.author.save(success => {
  console.log('author saved!');
});

Pagination

let authors = AuthorsService.all(
  {
    // get page 2 of authors collection, with a limit per page of 50
    page: { number: 2 ;  limit: 50 }   
  }
);

Collection page

  • number: number of the current page
  • limit: limit of resources per page (it's sended to server by url)
  • information returned from server (check if is avaible) total_resources: total of avaible resources on server resources_per_page: total of resources returned per page requested

Local Demo App

You can run JsonApi Demo App locally following the next steps:

git clone [email protected]:reyesoft/ts-angular-jsonapi.git
cd ts-angular-jsonapi
npm install -g gulp   # if you are on linux, you need do this with sudo
npm install
gulp serve

We use as backend Json Api Playground.

Colaborate

First you need run the demo. Next, when you made new features on your fork, please run

gulp dist

And commit! Don't forget your pull request :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].