Closed csulit closed 1 year ago
@csulit It does work, you just need to import the right addon.
import wretch from "wretch";
import QueryStringAddon from "wretch/addons/queryString";
wretch("http://example.com")
.addon(QueryStringAddon)
.query({ name: "test" })
Please read the documentation: https://github.com/elbywan/wretch#querystring-
@elbywan why adding query from instance not possible? I wanted to use from one created wretch instance everywhere in my app like this
// api.ts
import wretch from 'wretch';
import QueryStringAddon from 'wretch/addons/queryString'
import { store } from './store';
const token = store.getState().auth.token;
export const api = wretch()
.addon(QueryStringAddon)
.auth(`Bearer ${token}`)
.catcher(401, () => {
// clear token and redirect to login
store.dispatch({ type: 'auth/logout' });
})
// another_files.ts example usage
api.get('/users').query({ page: 1 }).json() // but this doesn't work
Ok I found this way of working, but the way I showed rather intuitive for me
api.url('/users').query({ page: 1 }).get().json() // this is working
.get().query({name: "test"}) not working?? how to pass query params?