@m92/http-client-fe-v2
v1.0.0
Published
Web http Client using axios with JWT Authentication & JOSE Encrytion.
Downloads
5
Readme
http-client-fe-v2
http-client-fe-v2 is a custom http-request package for browser with in-built support for JOSE (JWE) encryption. The ready package for backed could be found at
Installation and Setup
ReactAppBoilerplate
If you're using ReactAppBoilerplate as recommended, requires 4 step configuration:
- Create Config File
// src/configurations/network/HTTP_CLIENT_CONFIG.js
import API_ROUTES from './API_ROUTES'
const { REACT_APP_ENABLE_CRPTOGRAPHY = '', REACT_APP_API_KEY } = process.env
const ENABLE_CRPTOGRAPHY = REACT_APP_ENABLE_CRPTOGRAPHY.trim().toLowerCase() === 'true'
const HTTP_CLIENT_CONFIG = {
ENABLE_CRPTOGRAPHY,
API_KEY: REACT_APP_API_KEY,
API_ROUTES
}
export default HTTP_CLIENT_CONFIG
- Create Constants File
// src/configurations/network/HTTP_CLIENT_CONSTANTS.js
const { API_TIMEOUT } = process.env
const TIMEOUT = API_TIMEOUT || 3000
const HTTP_CLIENT_CONSTANTS = {
TIMEOUT
}
export default HTTP_CLIENT_CONSTANTS
- Create HttpClient File
import HttpClientClass from '@m92/http-client-fe-v2'
import HTTP_CLIENT_CONFIG from 'configurations/network/HTTP_CLIENT_CONFIG'
import HTTP_CLIENT_CONSTANTS from 'configurations/network/HTTP_CLIENT_CONSTANTS'
const HttpClient = new HttpClientClass(HTTP_CLIENT_CONFIG, HTTP_CLIENT_CONSTANTS)
export default HttpClient
- Inject HttpClient in Redux Thunk
// src/configurations/redux/store.js
.....
import HttpClient from '//path/to/HttpClient/File'
.....
const middlewares = [
thunk.withExtraArgument({ HttpClient }) // Argument can be a request object used inside all calls
]
.....
License
MIT