Skip to content

Sunday TYPESCRIPT outfoxx/sunday-js

A Sunday client library implementation written in TypeScript, supporting modern web browsers and similar JavaScript environments.


Tip

While you can use Sunday (TypeScript) to write REST clients manually, Sunday is most useful when generating clietns from API definitions using the Sunday Generator.

Learn about Sunday Generator

Installation

Sunday is delivered as standard NPM package that can be consumed by TypeScript and JavaScript projects.

Package Name

    outfoxx/sunday-js

Current Release

1.1.0-beta.5

Usage

Initializing Service Clients

Service clients need to be initialized with an RequestFactory implementation to adapt service methods into network requests.

Sunday's standard implementation of RequestFactory, named FetchRequestFactory, is based on the Fetch Web API.

You initialize the FetchRequestFactory with a base URL, which can be a URI template if necessary:

const requestFactory = new FetchRequestFactory("https://example.com/api/v1");

Customizing Requests

If needed, you can pass an adapter to the constructor to customize generated requests. The adapter allows you to add authorization headers, change the URL or make any other changes needed to requests generated by the library.

const requestFactory = new FetchRequestFactory("https://example.com/api/v1", {
  adapter: (request) => {
    request.headers.set("Authorization", `Bearer ${accessToken}`);
    return Observable.from(request);
  },
});

License

Copyright 2020 Outfox, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.