sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
MIT License
11.83k stars 341 forks source link

Add baseUrl option, rename prefixUrl, and allow leading slashes in input #606

Open sholladay opened 4 days ago

sholladay commented 4 days ago

This PR aims to improve the flexibility of input URLs and options for resolving them prior to the request.

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

TODO: