@seagull/services-http

Http services for the seagull framework

Usage no npm install needed!

<script type="module">
  import seagullServicesHttp from 'https://cdn.skypack.dev/@seagull/services-http';
</script>

README

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.