Skip to content

Instantly share code, notes, and snippets.

@DeVoresyah
Created June 20, 2020 08:03
Show Gist options
  • Save DeVoresyah/cc671077b467e04ea08015442807ea18 to your computer and use it in GitHub Desktop.
Save DeVoresyah/cc671077b467e04ea08015442807ea18 to your computer and use it in GitHub Desktop.
Standard ApiSauce
import apisauce from 'apisauce'
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Token 31beacea1ac15388c00c3eff86c3231b/LQ0W9fSPOrbdeYZSrlFSChSRmYLNhGUY//GvEXfRZmDH6PzDdW8D1rlOMIJj2zX',
}
// our "constructor"
const create = (baseURL = 'http://localhost:3333/api/client/v1') => {
const api = apisauce.create({
// base URL is read from the "constructor"
baseURL,
// here are some default headers
headers: headers,
// 10 second timeout...
timeout: 10000
})
// api.addResponseTransform(response => {
// if (!response.ok) {
//
// let msgError = "No Internet Connection"
// if (response.data && response.data.data && response.data.data.message) {
// msgError = response.data.data.message
// }
//
// response.data = {
// response: {
// status: 404,
// message: msgError
// },
// data: {
// message: msgError
// }
// }
// }
// })
// Auth
const authLogin = (data) => api.post(`/auth/login`, data)
const authRegister = (data) => api.post(`/auth/register`, data)
// Profile
const getProfile = (data) => api.get(`/profile`, data)
// Gate
const getGate = (data) => api.get(`/gate`, data)
// Payment Method
const getPaymentMethod = (data) => api.get(`/payment-method`, data)
// Topup Pack
const getTopupPack = (data) => api.get(`/topup-pack`, data)
const createTopup = (data) => api.post(`/topup/new`, data)
return {
// Auth
authLogin,
authRegister,
// Profile
getProfile,
// Gate
getGate,
// Payment Method
getPaymentMethod,
// Topup Packa
getTopupPack,
createTopup,
api,
headers,
}
}
// let's return back our create method as the default.
export default {
create
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment