
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
Angular2 API services that wrap Http. See full client and server example ng2-api-examples
npm i --save ng2-api
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
export function authenticated(): boolean {
return !!localStorage.getItem('token');
}
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) {}
canActivate() {
if (authenticated()) { return true; }
// Navigate to the login page
this.router.navigate(['/login']);
return false;
}
}
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { ApiHttp } from 'ng2-api';
import { authenticated } from './auth.guard';
@Injectable()
export class AuthService {
user: Object;
authenticated: boolean = authenticated();
constructor(protected http: ApiHttp,
protected router: Router) {
try {
this.user = JSON.parse(localStorage.getItem('profile'));
} catch(e) {
this.user = {};
}
}
login(params: any) {
return this.http.post('login', JSON.stringify(params))
.subscribe((res: Response) => {
let {token, user} = res.json();
let {token, user} = {token: 'abc', user: params};
localStorage.setItem('profile', JSON.stringify(user));
this.http.config.token = token;
this.authenticated = true;
this.user = user;
this.router.navigate(['/admin/posts']);
});
}
logout() {
localStorage.removeItem('profile');
this.http.config.token = '';
this.authenticated = false;
this.user = null;
this.router.navigate(['/login']);
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule, Http } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { ApiConfig, ApiHttp } from './ng2-api';
import { AppComponent } from './app.component';
import { AuthService } from './shared/auth.service';
import { PostsComponent } from './posts/posts.component';
import { PostsService } from './posts/posts.service';
import { routing } from './app.routing';
@NgModule({
imports: [
BrowserModule,
HttpModule,
FormsModule,
routing
],
declarations: [
AppComponent,
PostsComponent,
],
providers: [
{
provide: ApiHttp,
useFactory: (http: Http) => new ApiHttp(new ApiConfig({baseUrl: '/api'}), http),
deps: [Http]
},
AuthService,
PostsService,
],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Injectable } from '@angular/core';
import { ApiService } from 'ng2-api';
export interface Post {
id?: number;
title: string;
body: string;
}
@Injectable()
export class PostsService extends ApiService<Post> {
constructor(protected http: ApiHttp) {
super(http, 'posts');
}
}
find(id: number | string): Observable<Post>
findAll(search?: any): Observable<Post[]>
create(model: Post): Observable<Post>
update(model: Post): Observable<Post>
delete(model: Post): Observable<boolean>
You can customize resource path and provide optional config to super().
If need, you can also overwrite ApiService public (i.e. update) and private methods (i.e. serialize, deserialize)
Example:
@Injectable()
export class PostsService extends ApiService<Post> {
constructor(protected http: ApiHttp) {
super(http, 'posts', {
arrayRoot: 'posts',
objectRoot: 'post'
});
}
}
npm i
npm test
MIT
FAQs
Angular2 API services
The npm package ng2-api receives a total of 3 weekly downloads. As such, ng2-api popularity was classified as not popular.
We found that ng2-api 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
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.