@seagull/services-http
TypeScript icon, indicating that this package has built-in type declarations

20.0.5 • 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.

Package Sidebar

Install

npm i @seagull/services-http

Weekly Downloads

11

Version

20.0.5

License

LGPL-3.0

Unpacked Size

110 kB

Total Files

85

Last publish

Collaborators

  • anonyfox
  • harper04
  • aduril
  • maikman
  • mr_soundcool
  • cpa-aida
  • sakeco1337