Comments (4)
Hi and thanks for the awesome lib!
Hi @mvasin, thanks!
Is there a way to get response headers when using wretch? I wasn't able to find anything in the docs.
Yes, you can get the headers them by using .res()
to retrieve the raw fetch response object.
// see it in action here: https://runkit.com/embed/ydiucqoe45xu
wretch('...').get().res(res => {
// 'res' is the raw response (see https://developer.mozilla.org/en-US/docs/Web/API/Response)
// 'res.headers' contains the Headers (https://developer.mozilla.org/en-US/docs/Web/API/Headers)
console.log(Array.from(res.headers.entries()))
return res.text()
}).then(console.log)
from wretch.
If you need both headers and the json data, here's how I did it:
.res(response => {
// do something with response.headers
return res.json(); // or res.text() if you need text
})
.then(json => {...})
from wretch.
I had the same question myself and just wanted to att that this works response.headers.get('location')
from wretch.
What is the best way to pass headers further alongside with json data to resolve in then block ?
const successHandler = response => {
console.log({response})
if (response.status === 201) {
let authToken = response.data["auth-token"];
let { client } = response.data;
let sessionCookie = response.headers["set-cookie"][0];
onSuccess(authToken, sessionCookie, client);
} else {
errorHandler();
}
};
from wretch.
Related Issues (20)
- 2.7.1 is causing a terser issue in my applications HOT 6
- How to add a hook that always runs on success and failure? HOT 2
- [QUESTION] How can I add generic here? HOT 6
- Handling 302 redirects HOT 1
- Retry middleware does not handle other side closing unexpectedly HOT 4
- Retry Middleware HOT 6
- Unable to resolve any addon in Expo React Native project HOT 4
- Generic way to replay requests for all awaited methods HOT 1
- How to send (object manually converted to) FormData instance? HOT 4
- Basic auth middleware/extension HOT 1
- Type issue with `QueryStringAddon` and `resolve` HOT 2
- progress addon not working with Put? HOT 1
- How to extract catcher functions with TypeScript HOT 1
- wretch and nextjs caching HOT 1
- No nice way to handle 202 Accepted HOT 2
- QueryStringAddon converts `undefined` values into empty strings instead of omitting them HOT 2
- Wretch loses the request body for the PUT, POST, and PATCH methods if it is FormData
- Is it possible to read error.response.body inside of an error? HOT 3
- Not clear how to type a precomposed Wretch object HOT 2
- wretch throws error on redirect response HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wretch.