Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ember-data/request-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Utilities for Requests
This package provides Simple utility function to assist in url building, query params, and other common request operations.
It's built for EmberData but useful more broadly if you're looking for lightweight functions to assist in working with urls and query params.
Installation
Install using your javascript package manager of choice. For instance with pnpm
pnpm add @ember-data/request-utils
Utils
As a Library Primitive
These primitives may be used directly or composed by request builders to provide a consistent interface for building requests.
For instance:
import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
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!):
import { query } from '@ember-data/rest/request';
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.