Need private packages and team management tools?Check out npm Teams »

@seagull/services-http

18.0.2 • Public • Published

http (injectable)

Injectable library for http requests using http-fetch.

  • Implements seagull environment mode (cloud, connected, edge, pure)
  • Implements seed data generation for test cases

Usage

The basic fetch function can be called like this:

import { Http } from '@seagull/services-http'
...
class ... {
  // inject http implementation
  constructor(private http: Http) {}
  doSomething() {
    const response = await this.http.get(url)
    const json = await response.json()
  }
}

For convinience, you can use a content-specific adapters as well:

import { HttpJson } from '@seagull/services-http'
...
class ... {
  // inject http implementation
  constructor(private http: HttpJson) {}
  doSomething() {
    try {
      const json = this.http.get(url)
    } catch (err) {
      ...
    }
 
  }
}

Bootstrap

import { containerModule } from '@seagull/services-http'
import { Container } from 'inversify'
 
const injector = new Container()
injector.load(containerModule)

Mode behavior

  • cloud : returns response of the external resource (as defined via url/config)
  • connected : same as cloud
  • edge : same as cloud
  • pure : returns local seed data (throws an error if no seed data is available)

Configuration hooks

See @seagull/seed README for details.

Install

npm i @seagull/services-http

DownloadsWeekly Downloads

1

Version

18.0.2

License

LGPL-3.0

Unpacked Size

110 kB

Total Files

85

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar