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

@nativecode/rest-client

2.2.3-next.0 • Public • Published

@nativecode/rest-client

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

Install

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.2.3-next.0

License

MIT

Unpacked Size

34.9 kB

Total Files

32

Last publish

Collaborators

  • avatar
  • avatar
  • avatar