Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@iruizr7/ngx-jsonapi
Advanced tools
You can test library on this online example 👌 http://ngx-jsonapi.reyesoft.com/.
Data is obtained from Json Api Playground server.
Just install, configure and learn with examples.
First of all, it's advisable to read Jsonapi specification. Understanding JsonApi documents structure is recommended.
yarn add ngx-jsonapi@2.0.0-rc.4 --save
# or npm if you wish...
Jsonapi.Resource
./* .. */
import { NgxJsonapiModule } from 'ngx-jsonapi';
@NgModule({
imports: [
NgxJsonapiModule.forRoot({
url: '//jsonapiplayground.reyesoft.com/v2/'
})
]
})
export class AppModule {}
Library cache anything memory. With Local Store, also store all on IndexDb on browser. Faster apps when we reuse a lot of data.
/* .. */
import { NgxJsonapiModule } from 'ngx-jsonapi';
import { JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
import { StoreService } from 'ngx-jsonapi/sources/store.service';
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
@NgModule({
imports: [
NgxJsonapiModule.forRoot({
url: '//jsonapiplayground.reyesoft.com/v2/'
})
],
providers: [
{
provide: JSONAPI_RIPPER_SERVICE,
useClass: JsonRipperFake
},
{
provide: JSONAPI_STORE_SERVICE,
useClass: StoreFakeService
}
]
})
export class AppModule {}
Like you know, the better way is with examples. Lets go! 🚀
authors.service.ts
import { Injectable } from '@angular/core';
import { Autoregister, Service, Resource, DocumentCollection, DocumentResource } from 'ngx-jsonapi';
import { Book } from '../books/books.service';
import { Photo } from '../photos/photos.service';
export class Author extends Resource {
public attributes = {
name: 'default name',
date_of_birth: ''
};
public relationships = {
books: new DocumentCollection<Book>(),
photo: new DocumentResource<Photo>()
};
}
@Injectable()
@Autoregister()
export class AuthorsService extends Service<Author> {
public resource = Author;
public type = 'authors';
}
import { Component } from '@angular/core';
import { DocumentCollection } from 'ngx-jsonapi';
import { AuthorsService, Author } from './../authors.service';
@Component({
selector: 'demo-authors',
templateUrl: './authors.component.html'
})
export class AuthorsComponent {
public authors: DocumentCollection<Author>;
public constructor(private authorsService: AuthorsService) {
authorsService
.all({
// include: ['books', 'photos'],
})
.subscribe(authors => (this.authors = authors));
}
}
<p *ngFor="let author of authors.data; trackBy: authors.trackBy">
id: {{ author.id }} <br />
name: {{ author.attributes.name }} <br />
birth date: {{ author.attributes.date_of_birth | date }}
</p>
Example: name
is a authors attribute, and makes a query like /authors?sort=name,job_title
let authors = authorsService.all({
sort: ['name', 'job_title']
});
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.
authorsService.all({
remotefilter: { country: 'Argentina' }
});
From this point, you only see important code for this library. For a full example, clone and see demo directory.
authorsService.get('some_author_id');
authorsService.get('some_author_id', { include: ['books', 'photos'] });
TIP: these parameters work with all()
and save()
methods too.
let author = this.authorsService.new();
author.attributes.name = 'Pablo Reyes';
author.attributes.date_of_birth = '2030-12-10';
author.save();
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 = booksService.get(1);
author.addRelationship(some_book);
// some_publisher is a polymorphic resource named company on this case
let some_publisher = 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)
);
authorsService.get('some_author_id').suscribe(author => {
this.author.attributes.name += 'New Name';
this.author.save(success => {
console.log('author saved!');
});
});
authorsService.all({
// get page 2 of authors collection, with a limit per page of 50
page: { number: 2 ; size: 50 }
});
You can run JsonApi Demo App locally following the next steps:
git clone git@github.com:reyesoft/ngx-jsonapi.git
cd ngx-jsonapi
yarn
yarn start
We use as backend Json Api Playground.
Check Environment development file 😉.
FAQs
JSON API library for Angular
The npm package @iruizr7/ngx-jsonapi receives a total of 0 weekly downloads. As such, @iruizr7/ngx-jsonapi popularity was classified as not popular.
We found that @iruizr7/ngx-jsonapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.