This PR aims to improve the flexibility of input URLs and options for resolving them prior to the request.
prefixUrl is renamed to startPath
As before, when this option is used, it is prepended to input before any other processing takes place
startPath can still be a full URL if needed, however the name is meant to signal its primary use case is a simple base path without a domain, e.g. /api
A new baseUrl option is added
When this option is used, input (including any startPath) is resolved against the baseUrl according to standard URL resolution rules
baseUrl will respect the HTML <base> tag if present, and is similar to it, except that it only applies to Ky
input can now be any valid URL, with or without a leading slash
Slashes are automatically normalized when using startPath
Slashes are kept as-is and respected in accordance with standard URL resolution rules when using baseUrl
ky('books', { startPath : '/api' }); // GET /api/books
ky('books', { baseUrl : '/api' }); // GET /books
ky('books', { baseUrl : '/api/' }); // GET /api/books
ky('./books', { baseUrl : '/api/' }); // GET /api/books
ky('/books', { baseUrl : '/api/' }); // GET /books
ky('http://bar.com', { startPath : 'http://foo.com' }); // GET http://foo.com/http://bar.com
ky('http://bar.com', { baseUrl : 'http://foo.com' }); // GET http://bar.com
ky('books', { baseUrl : 'http://foo.com', startPath : '/api' }); // GET http://foo.com/api/books
Possible names for the string that is prepended to input
This PR aims to improve the flexibility of input URLs and options for resolving them prior to the request.
prefixUrl
is renamed tostartPath
input
before any other processing takes placestartPath
can still be a full URL if needed, however the name is meant to signal its primary use case is a simple base path without a domain, e.g./api
baseUrl
option is addedinput
(including anystartPath
) is resolved against thebaseUrl
according to standard URL resolution rulesbaseUrl
will respect the HTML<base>
tag if present, and is similar to it, except that it only applies to Kyinput
can now be any valid URL, with or without a leading slashstartPath
baseUrl
Possible names for the string that is prepended to
input
startPath
(as is currently implemented here)pathPrefix
prefixPath
rootPath
TODO:
startPath
option