![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
axios-typescript-response
Advanced tools
Get axios AJAX response in typescript class objects
- npm install axios-typescript-response
http.get(url: string, type: (new (arg: any) => T), useConstructor: Boolean, config?: AxiosRequestConfig | undefined)
- url: API url
- type: Expected data type to be returned from the API
- useConstructor: Indicates if the class constructor should be used (false by default)
- config: Axios configuration if needed
http.post(url: string, payload: any, type: (new (arg: any) => T), useConstructor: Boolean, config?: AxiosRequestConfig | undefined): Promise
- url: API url
- payload: Data that will be put in the request body
- type: Expected data type to be returned from the API
- useConstructor: Indicates if the class constructor should be used (false by default)
- config: Axios configuration if needed
class Post{
id: number = 0;
userId: number = 0;
title: string = '';
body: string = '';
}
import Http from 'axios-typescript-response';
...
http
.get<Post>("https://jsonplaceholder.typicode.com/posts/1", Post)
.then((response) => console.log(response instanceof Post))
//result in console is true
axios
.get<Post>("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => console.log(response.data instanceof Post))
//result in console is false
class Post{
constructor(obj:any = {}){
this.id = obj.id;
this.userId = obj.userId;
this.title = obj.title;
this.body = obj.body;
}
id: number;
userId: number;
title: string;
body: string;
}
import Http from 'axios-typescript-response';
...
http
.get<Post>("https://jsonplaceholder.typicode.com/posts/1", Post, true)
.then((response) => console.log(response instanceof Post))
//result in console is true
axios
.get<Post>("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => console.log(response.data instanceof Post))
//result in console is false
To add additional axios configuration, you must import the class instance and create the http object after the configuration is added.
import axios from 'axios';
import store from '../store/store';
import router from '../router/router';
import { Http } from 'axios-typescript-response';
axios.interceptors.request.use(config => {
config.baseURL = store.getters.baseUrl;
//Auth token
const token = store.state.user!.token;
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
//Culture
config.headers["Accept-Language"] = store.getters.Language;
config.headers["Accept"] = '*/*';
return config;
});
// Add a 401 response interceptor
axios.interceptors.response.use(response => {
return response;
}, function (error) {
if (401 === error.response.status) {
store.dispatch('logout').then(() => {
router.push('/login');
});
} else {
return Promise.reject(error);
}
});
export default new Http();
FAQs
Get axios AJAX response in typescript class objects
The npm package axios-typescript-response receives a total of 6 weekly downloads. As such, axios-typescript-response popularity was classified as not popular.
We found that axios-typescript-response demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.