axios-transform-validate-response
v0.1.15
Published
Plugin to transform and validate axios responses using typestack class-transformer and class-validator.
Downloads
42
Maintainers
Readme
axios-transform-validate-response
Plugin to transform and validate axios responses using typestack class-transformer and class-validator.
Usage
At some point in your application apply the plugin as default response transformer:
axios.defaults.transformResponse = classTransformValidateResponse;
To apply the transformer use the requests config as follows:
await axios.get('https://api.example.com', {
classTransformConfig: {
targetClass: TestClass, // <- Class to transform the response to
dataRetriever: (data: any) => data.data // <- (optional) Function to retrieve the data from the response
}
});
Typings
To stop your IDE from yelling at you about the classTransformConfig
property, you can add the following typings to your project:
export * from "axios-transform-validate-response";
Test
Run npm test