Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@nativecode/rest-client

0.0.2-canary.131 • 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._get('models')
  }
 
  byId(id: number): Promise<Model> {
    return this._get('models/{:id}', [
      {
        key: 'id',
        type: RestResourceParamType.RouteParameter,
        value: id,
      }
    ])
  }
}
 

Install

npm i @nativecode/[email protected]

Version

0.0.2-canary.131

License

MIT

Unpacked Size

28.7 kB

Total Files

24

Last publish

Collaborators

  • avatar
  • avatar
  • avatar