HTTP Response Best Practice

Cing Sian Dal
May 5, 2021

--

Normally your response JSON contains data property. We just simply retrive data with simple format.

const { data } = response; // data = true
if(data){
// do something
}

Well, it is not well format. As a best practice, it is better to respond with well format.

const { data } = response;
const { isAvailable } = data; // data: { isAvailable: true }
if(data){
// do something
}

--

--

Cing Sian Dal
Cing Sian Dal

Written by Cing Sian Dal

Don’t follow me. I wrote junks here. Follow me on Twitter instead.

No responses yet