Some use-cases may require allowing an empty URL
See original GitHub issueIs your feature request related to a problem? Please describe.
I’d like to give some feedback for the axios 0.25 release. #3791 introduces a fast failure when an empty string is provided as a URL to the request builder. However, my own and at least one other project are intentionally using empty strings as URLs and the 0.25 release breaks working code. It is listed as a breaking change in the changelog, but the behavior may be unpractical for some use-cases: Let’s imagine a service abstraction over a RESTful resource; the baseURL could be something like http://example.com/examples, avoiding passing /examples as a path with each request. A GET or POST request using "" as a URL would be valid in this case.
Describe the solution you’d like
- Is it possible for the request builder to accept empty strings but fail for undefined?
- Or maybe some config option could be introduced to intentionally opt out of the fast failure.
- An obscure solution would be to additionally pass the
baseURLasurltoaxios.create, but currently the presence of the URL is checked before merging the configs. Moving theif (!config.url) {part down after the config merge would allow this escape hatch.
I’d be happy to submit a PR if desired.
Describe alternatives you’ve considered
- Changing the respective occurrences in my code.
- Using a slash or a space as a URL would work in many cases but it would also introduce trailing slashes.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:33
- Comments:21 (5 by maintainers)
Top Results From Across the Web
Is it a good practice to use an empty URL for a HTML form's ...
@Kerrick Yes, I believe HTML5 allows omitting the action attribute entirely, and defaults it to empty string. HTML4 did not, it specifies action...
Read more >Using presigned URLs - Amazon Simple Storage Service
Use a presigned URL to share or upload objects in Amazon S3 without requiring AWS security credentials or permissions.
Read more ><input type="url"> - HTML: HyperText Markup Language | MDN
The input value is automatically validated to ensure that it's either empty or a properly-formatted URL before the form can be submitted.
Read more >Referer and Referrer-Policy best practices - web.dev
All policies that take the scheme (HTTPS vs. HTTP) into account ( strict-origin , no-referrer-when-downgrade and strict-origin-when-cross- ...
Read more >Tag your Google Ads final URLs - Analytics Help
Special cases · Your website doesn't allow arbitrary URL parameters · You need to use auto-tagging for non-Analytics purposes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

We could potentially change the name to path, then make it not required, then this might make more sense, people can then implement
baseUrland leave out path. Does this sound like a better solution?We can also use a mapper to allow some backward compatibility with url to start off with and then add warnings and remove.
Changes made with #4426 will release soon