-
-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document the behavior of the baseUrl
option
#562
Comments
That is a bug. I incorrectly assumed the (new URL('/foo', 'https://sindresorhus/unicorn')).toString();
//=> 'https://sindresorhus/foo' We should also update the |
baseUrl
should support common url
In my defence, the MDN docs are not clear at all about this:
|
em, cuz the we just need to support the path part |
@marswong I think you misunderstood. It's indeed a bug in Got. We need to handle the path part, yes. |
This example is correct (because baseUrl is missing (new URL('/foo', 'https://sindresorhus/unicorn')).toString();
//=> 'https://sindresorhus/foo' However this is a common mistake ( (new URL('/foo', 'https://sindresorhus/unicorn/')).toString();
//=> It returns 'https://sindresorhus/foo' but we expected 'https://sindresorhus/unicorn/foo' There are three ways to fix this:
(new URL('foo', 'https://sindresorhus/unicorn/')).toString();
//=> 'https://sindresorhus/unicorn/foo'
(new URL('./foo', 'https://sindresorhus/unicorn/')).toString();
//=> 'https://sindresorhus/unicorn/foo'
I'd just update the docs about that behaviour :) |
@szmarczak Ah, I totally missed that. I think the current behavior is ok, but we should make it much clearer in the docs. |
@szmarczak sorry, have u tried with |
@marswong Got 9:
Output:
It works as expected. |
baseUrl
should support common urlbaseUrl
option
@szmarczak i try your sample, it works. just the (async () => {
const instance = got.extend({ baseUrl: 'https://api.douban.com/v2' });
const id = 1220562;
const body = (await instance.get(`book/${id}`)).body;
console.log(body);
})(); so it should be noted in the doc, thanks :) |
In my opinion, this should be
So the things @szmarczak and @marswong mentioned should be in the docs: |
@szmarczak Is there a technical reason the |
It's an expected behaviour, but it may be confusing. I'd leave that as it is. If you prefer the second way, we could throw an error if baseUrl doesn't end with |
Why is it an expected behavior? It's not like |
Why it isn't?
This is the current behavior (which is fine). So, the absolute URL is WHATWG URL says:
So what @marswong wanted is a Anyway, like @beac0n has mentioned, I'd just update the docs. |
I commented that above. Because it's not like how
I'm confused. We have already established it is not the current behavior. (#562 (comment))
This example is invalid. I can't really reply until I know what you were trying to argue.
Why not just append the |
Let's skip what I said then, it doesn't really matter because as you've pointed out, we were talking about different things, and I agree.
That behavior would be confusing (at least for me with the behaviour of the |
Why? The workflow for the user of the package would then be: Why not just add a slash at the end of baseUrl if none is present? The outcome would be the same for the user. We should at most log a warning or something like that. However, I would prefer to document this thoroughly and the keep the code unchanged, as it would give the user the freedom to use the package as he/she sees fit. |
Please see my previous answer:
I can ask the opposite, right? :) I don't say no, but just in case to be safe. Similar thing was about the |
Ok, I think we've received enough feedback to make a decision :)
So let's do it 👍 We need to document it clearly.
I think it's OK then. |
in common senarios, we used to deploy our api with a url
{host}/api
, so we may usegot
like this:somehow, cuz the
baseUrl
just support a WHATWG URL currently, we have to add a/api/v1
prefix for each url and it really sucks for tons of long urls.The text was updated successfully, but these errors were encountered: