Skip to content

Instantly share code, notes, and snippets.

@besingamkb
Created September 6, 2016 15:25
Show Gist options
  • Save besingamkb/c1a4db3afd5a89847c6cfabd9fb8b520 to your computer and use it in GitHub Desktop.
Save besingamkb/c1a4db3afd5a89847c6cfabd9fb8b520 to your computer and use it in GitHub Desktop.
authentication using apisauce for react-native
// a library to wrap and simplify api calls
import apisauce from 'apisauce'
import Reactotron from 'reactotron' // for IOS
const create = (baseURL = 'http://projectsnap.dev/api') => {
const api = apisauce.create({
// base URL is read from the "constructor"
baseURL,
// here are some default headers
headers: {
'Cache-Control': 'no-cache'
},
// 10 second timeout...
timeout: 10000
})
const login = (email, pword) => api.post('/authenticate', {email: email, password: pword})
const apiMonitor = (response) => {
console.log("monitoring initiated")
console.log(JSON.stringify(response))
}
api.addMonitor(apiMonitor)
return {
api,
login
}
}
// 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