DEV Community

Discussion on: My Fetch Wrapper with async/await and TypeScript

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

POST is OK, but GET shouldn't have a response body. You should use querystrings.

Collapse
 
avxkim profile image
Alexander Kim

Yeah, that's why i set body to undefined by default, when calling this wrapper you also can omit a body.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

You still have application/json header, which is affected by CORS.

Now, my goto is axios, which auto-detect body type

  • GET + { params: Object } => will convert URL to querystring. No header needed
  • POST + { data: Object } => application/json
  • POST + { data: Stringified query string } => application/x-www-form-urlencoded

Axios also allowes raise_for_status and error interceptors.

However, axios uses XMLHttpRequest. Not sure if this matters.

Thread Thread
 
avxkim profile image
Alexander Kim • Edited

Well, i've used axios with Vue a lot, it's more convenient, tbh. But it's an additional dependency, also they are not actively working on currently stalled issues in their repo. Axios has many neat features built-in. But i wonder about the future of this project.