2.3.0 • Published 9 months ago

@open-pioneer/http v2.3.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

@open-pioneer/http

This package provides the HttpService, which can be used to request resources over HTTP.

Usage

To use the HTTP service, reference the interface http.HttpService from your service as in the following sample:

// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";

export default defineBuildConfig({
    services: {
        MyService: {
            references: {
                httpService: "http.HttpService"
            }
        }
        // ...
    }
    // ...
});

From the implementation class of MyService, call fetch() on the service:

// MyService.js
export class MyService {
    constructor(serviceOptions) {
        this.httpService = serviceOptions.references.httpService;
    }

    async myMethod() {
        const response = await this.httpService.fetch(/* ... */);
    }
}

The signature of the fetch() method is compatible to the Browser's global fetch function. However, the HttpService's method should be preferred to take advantage of future features (such as logging or proxy support).

Request interceptors

The request interceptor API is experimental: it may change with a new minor release as a response to feedback.

The HttpService supports extension via request interceptors. Request interceptors can modify requests (query parameters, headers, etc.) before they are sent to the server.

To register a request interceptor, implement a service that provides "http.Interceptor":

// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";

export default defineBuildConfig({
    services: {
        ExampleInterceptor: {
            provides: "http.Interceptor"
        }
        // ...
    }
    // ...
});
// ExampleInterceptor.ts
import { Interceptor, BeforeRequestParams } from "@open-pioneer/http";
export class ExampleInterceptor implements Interceptor {
    async beforeRequest?(params: BeforeRequestParams) {
        // Invoked for every request. See API documentation for more details.
    }
}

License

Apache-2.0 (see LICENSE file)

2.3.0

9 months ago

2.2.0

10 months ago

2.1.9

11 months ago

2.1.6

1 year ago

2.1.8

12 months ago

2.1.7

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

2 years ago

2.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

2.0.0

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago