Registry / devops / ng2-rest

ng2-rest

JSON →
library21.0.52jsnpmunverified

Robust isomorphic REST framework for browser (Angular, React, Vue) and backend (NodeJS/TypeScript) apps. Version 21.0.52. Built on axios as an alternative to Angular's HttpClient. Features: RxJS interop, JSONP support, class instance transfer between client/server, Express-style route definitions. Backed by the Taon ecosystem. Currently in active development with frequent releases.

npm install ng2-rest
INSTALL
IMPORT
SIG · NG2-REST
N
ng2-rest
devopsjavascriptv21.0.52
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Resource
import { Resource } from 'ng2-rest/browser'
import { Resource } from 'ng2-rest'
Import from 'ng2-rest/browser' for browser usage; for Node/backend use 'ng2-rest/node'
Resource
const { Resource } = require('ng2-rest/browser')
const Resource = require('ng2-rest')
CommonJS require must destructure and use the correct subpath 'browser'
Resource
import { Resource } from 'ng2-rest/browser'
import Resource from 'ng2-rest'
Resource is a named export, not default

Shows basic setup: import Resource, define a class, create a Resource endpoint, and make GET requests using both Promise and Observable patterns.

import { Resource } from 'ng2-rest/browser'; class User { name: string; surname: string; id: number; fullName() { return `Surname: ${this.surname}, Name: ${this.name}`; } } const rest = Resource.create<User>('http://yourbackend.com/api', 'users/:id', { '': User }); // Promise-based usage rest.model({ id: 1 }).get().then(({ body }) => { console.log(body.json); // User instance }); // Observable-based usage rest.model().array.get().observable.subscribe(({ body }) => { console.log(body.json); // User[] });
Debug
Known issues
breakingImport path changed to subpath exports: use 'ng2-rest/browser' or 'ng2-rest/node' instead of 'ng2-rest'
fix
Update imports to 'ng2-rest/browser' for browser, 'ng2-rest/node' for Node.js
affects: >=18.0.0
gotchaResource.create() third argument mapping must be an object with empty string key for root class mapping
fix
Use { '': YourClass } syntax, not just YourClass directly
affects: >=1.0.0
gotchaObservable responses are only available when using .observable property, expected from array.get().observable
fix
Chain .get().observable to get RxJS Observable; omit .observable for Promise
affects: >=1.0.0
deprecatedResource.enableWarnings = false; is the only documented configuration option
fix
No alternative, continue using this pattern
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'ng2-rest' or its corresponding type declarations.
Missing import subpath; using 'ng2-rest' instead of 'ng2-rest/browser' or 'ng2-rest/node'
fix
Use correct import: import { Resource } from 'ng2-rest/browser'
TypeError: Resource.create is not a function
Importing default export instead of named export Resource
fix
Use named import: import { Resource } from 'ng2-rest/browser' (note curly braces)
Property 'observable' does not exist on type 'Promise<...>'
Calling .observable on .get() without using .array first, or expecting Promise-like behavior
fix
Use rest.model().array.get().observable for Observable; rest.model().get() returns Promise
Upgrade
Version history
21.0.52latest on npm
Audit
Dependencies
rxjsoptionalUsed for observable support and operators like exhaustMap, switchMap
axiosrequiredUnderlying HTTP client used for requests
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
ng2-rest — npm install ng2-rest · libregistry