APINSPECTOR FOR REACT
Import this file in your ReactJS project to log the request and responses. Install APINSPECTOR desktop application and monitor the API logs.
Desktop applications are available for Windows, Linux & Mac
APINSPECTOR supports the following networking libraries in React.
- Axios
- Apisauce
- Fetch
Axios Sample Integration
Sample Axios file
import axios from "axios"
import logger from './logger'
let instance = axios.create({
baseURL: "server url",
timeout: 10000,
headers: {
"Content-Type": "application/json"
}
});
//Initialize logger with your API Key
logger.init("your APINSPECTOR apikey")
//Request interceptor
instance.interceptors.request.use( (config)=> {
return logger.getAxiosRequestConfig(config)
},
(error)=> {
return Promise.reject(error);
});
//Response interceptor
instance.interceptors.response.use(
response => {
logger.sendRequestMetrics(response)
return response.data
},
error => {
return null
});
export default class api {
static async getProfile(userid) {
return await instance.get("getprofile/"+userid)
}
}
APISAUCE Sample Integration
import {create} from 'apisauce';
import logger from './logger'
const api = create({
baseURL: "server url",
headers: {'Accept': 'application/json'},
});
//Initialize logger with your API Key
logger.init("your APINSPECTOR apikey")
//Request interceptor
api.addAsyncRequestTransform(config => async () => {
return logger.getAxiosRequestConfig(config)
},(error) => {
return Promise.reject(error);
})
//Response interceptor
api.addAsyncResponseTransform(response => async () => {
logger.sendRequestMetrics(response, 'apisauce')
return response.data
},error => {
return null
})
export default class api {
static async getProfile(userid) {
return await api.get("getprofile/"+userid)
}
}
Authors
- Anooj Krishnan G
- Sandeep Mishra
Licence
MIT