Documentation / @ember-data/request-utils / index / buildBaseURL
ts
function buildBaseURL(urlOptions): string;
Defined in: index.ts:316
Builds a URL for a request based on the provided options. Does not include support for building query params (see buildQueryParams
) so that it may be composed cleanly with other query-params strategies.
Usage:
ts
import { buildBaseURL } from '@ember-data/request-utils';
const url = buildBaseURL({
host: 'https://api.example.com',
namespace: 'api/v1',
resourcePath: 'emberDevelopers',
op: 'query',
identifier: { type: 'ember-developer' }
});
// => 'https://api.example.com/api/v1/emberDevelopers'
On the surface this may seem like a lot of work to do something simple, but it is designed to be composable with other utilities and interfaces that the average product engineer will never need to see or use.
A few notes:
resourcePath
is optional, but if it is not provided,identifier.type
will be used.host
andnamespace
are optional, but if they are not provided, the values globally configured viasetBuildURLConfig
will be used.op
is required and must be one of the following:- 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
- Depending on the value of
op
,identifier
oridentifiers
will be required.
Parameters
urlOptions
Returns
string