Skip to content
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

Remove .baseUrl and add a chainable way to append an url #8

Closed
elbywan opened this issue Oct 6, 2017 · 1 comment
Closed

Remove .baseUrl and add a chainable way to append an url #8

elbywan opened this issue Oct 6, 2017 · 1 comment

Comments

@elbywan
Copy link
Owner

elbywan commented Oct 6, 2017

Example :

// Old way : with baseUrl
const w = wretch().baseUrl("http://prefix.com/data")
w("/1").get()
w("/2").get()
// Oops ...
w.baseUrl("http://prefix.com/data/subdata")("/1").get()

// New way : With a flag ?
const w = wretch("http://prefix.com/data")
w.url("/1", true).get()
w.url("/2", true).get()
w.url("/subdata", true).url("/1", true).get()

// New way : Or with a new method ?
const w = wretch("http://prefix.com/data")
w.addUrl("/1").get()
w.addUrl("/1").get()
w.addUrl("/subdata").addUrl("/1").get()

// Or both ?

// Or simply make .url append instead of replacing urls ?
// My favourite, even if it's a breaking change I feel like it's more intuitive this way

const w = wretch("http://prefix.com/data")
w.url("/1").get()
w.url("/2").get()
w.url("/subdata").url("/1").get()

// With a 'replace' flag
w.url("http://test.com/", true)
@elbywan elbywan added this to the 1.0.0 milestone Oct 6, 2017
@elbywan elbywan self-assigned this Oct 6, 2017
elbywan added a commit that referenced this issue Oct 6, 2017
.url now appends by default, with a replace flag
Closes #8
@elbywan
Copy link
Owner Author

elbywan commented Oct 6, 2017

Implemented :

const w = wretch("http://prefix.com/data")
w.url("/1").get() // -> http://prefix.com/data/1
w.url("/2").get() // -> http://prefix.com/data/2
w.url("/subdata").url("/1").get() // -> http://prefix.com/data/subdata/1

// With a 'replace' flag
w.url("http://test.com/", true) // -> http://test.com/

Big syntax improvement over having both the baseUrl + url methods in my opinion !

@elbywan elbywan changed the title Remove .baseUrl and add a chainable way to append url Remove .baseUrl and add a chainable way to append an url Oct 6, 2017
elbywan added a commit that referenced this issue Oct 6, 2017
.url now appends by default, with a replace flag
Closes #8
@elbywan elbywan mentioned this issue Oct 6, 2017
@elbywan elbywan closed this as completed in 5142b02 Oct 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant