Miss any of our Open RFC calls?Watch the recordings here! »

@nativecode/rest-client

2.0.1 • Public • Published

rest-client

Provides an abstract REST compatible resource class using isomorphic-fetch to perform operations.

Installation

npm install @nativecode/rest-client

Usage

import { Resource } from '@nativecode/rest-client'
 
export class RestResource extends Resource {
  constructor(endpoint: URL, apikey: string, logger: Lincoln) {
    super(endpoint, logger)
    this.setHeader('x-api-key', apikey)
  }
 
  all(): Promise<Model[]> {
    return this.http_get('models')
  }
 
  byId(id: number): Promise<Model> {
    return this.http_get('models/{:id}', [
      {
        key: 'id',
        type: RestResourceParamType.RouteParameter,
        value: id,
      }
    ])
  }
}
 

Install

npm i @nativecode/[email protected]

Version

2.0.1

License

MIT

Unpacked Size

32.6 kB

Total Files

32

Last publish

Collaborators

  • avatar
  • avatar
  • avatar