@nativecode/rest-client
TypeScript icon, indicating that this package has built-in type declarations

2021.0.1 • 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,
      }
    ])
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @nativecode/rest-client

Weekly Downloads

0

Version

2021.0.1

License

MIT

Unpacked Size

51.7 kB

Total Files

56

Last publish

Collaborators

  • nativecode-dev
  • teegee
  • no-frills