Parse the API response into desired type using axios or any other helpful methods in JavaScript/React.js

26 Views Asked by At

I want to parse my api response into desired type and i don't want to loop/map the results to desired type or destruct the props after retrieval of response. Please do the response parse while receiving api response itself.

API response in desired format:

import Items from "./DetailsResponse";
export default interface MinimalApiResponse {
    Items: Items[];
    status: number;
    statusText: string;
  }

API call:

async getPolicies(detail: Detail): Promise<MinimalApiResponse> {
    try {
        const response: AxiosResponse<MinimalApiResponse> = await axios.post(this.searchUrl, detail);
        console.log(response);
    } catch (error) {
        throw error;
    }
}

I have specified the minimalapiresponse there but still not result parsed to that type i do see other props as well apart from what i specified in minimalapiresponse. Please suggest.

0

There are 0 best solutions below