Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apinspector-react

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apinspector-react

Import in your ReactJS project to log the request and responses. Install APINSPECTOR desktop application and monitor the API logs

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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.

  1. Axios
  2. Apisauce
  3. Fetch

Axios Sample Integration

Sample Axios file

import  axios  from  "axios"   
import  inspector  from  'apinspector-react'

let  instance  =  axios.create({    
    baseURL: "server url",    
    timeout: 10000,    
    headers: {    
    "Content-Type": "application/json"
    }
});

//Initialize logger with your API Key
inspector.init("your APINSPECTOR apikey")

//Request interceptor
instance.interceptors.request.use( (config)=> {   
    return  inspector.getAxiosRequestConfig(config)   
},    
(error)=> {    
    return  Promise.reject(error);    
});

//Response interceptor
instance.interceptors.response.use(    
response  => {    
    inspector.sendRequestMetrics(response,'axios')
    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 inspector from 'apinspector-react'

const api = create({

    baseURL: "server url",   
    headers: {'Accept': 'application/json'},

});

//Initialize logger with your API Key

inspector.init("your APINSPECTOR apikey")

//Request interceptor

api.addAsyncRequestTransform(config => async () => {

    return inspector.getAxiosRequestConfig(config)

},(error) => {    
    return Promise.reject(error);   
})

//Response interceptor

api.addAsyncResponseTransform(response => async () => {

    inspector.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

Keywords

FAQs

Package last updated on 27 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc