Skip to content
module@warp-drive/utilities

Simple utility function to assist in url building, query params, and other common request operations.

These primitives may be used directly or composed by request builders to provide a consistent interface for building requests.

For instance:

ts
import { buildBaseURL, buildQueryParams } from '@warp-drive/utilities';

const baseURL = buildBaseURL({
  host: 'https://api.example.com',
  namespace: 'api/v1',
  resourcePath: 'emberDevelopers',
  op: 'query',
  identifier: { type: 'ember-developer' }
});
const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
// => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'

This is useful, but not as useful as the REST request builder for query which is sugar over this (and more!):

ts
import { query } from '@warp-drive/utilities/rest';

const options = query('ember-developer', { name: 'Chris', include:['pets'] });
// => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
// Note: options will also include other request options like headers, method, etc.

Guides ​

  • Installation: install @warp-drive/utilities at the same version as @warp-drive/core.
  • Builders: write request builders, and keep cache keys stable with sortQueryParams, buildQueryParams and filterEmpty.
  • Making Requests: make a request with the findRecord builder, and the AutoCompress and Gate handlers.
  • Handlers: normalize a response with dasherize and singularize from @warp-drive/utilities/string.
  • Typing Requests: pass a response's meta type to the builders.
  • Basic Usage: configure setBuildURLConfig and page through results with the query builder.
  • Naming Conventions: how findRecord turns a resource type into a URL path.

Functions ​

Types ​

Released under the MIT License.