Narcoleptic Programmers' Medicine

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

    18.3.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

    15

    Version

    18.3.2

    License

    LGPL-3.0

    Unpacked Size

    110 kB

    Total Files

    85

    Last publish

    Collaborators

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