Skip to content

Instantly share code, notes, and snippets.

@akshay-nm
Last active November 4, 2020 13:42
Show Gist options
  • Save akshay-nm/42eec6ca6e6096158addf2d91c951245 to your computer and use it in GitHub Desktop.
Save akshay-nm/42eec6ca6e6096158addf2d91c951245 to your computer and use it in GitHub Desktop.
Example for raghav
// No alterations in stuff before this as it is already configured...
const api = () => {
return {
login: {
post: (email, password) => {
const formData = new FormData()
formData.append('email', email)
formData.append('password', password)
return configuredFetch({
url: getUrlFromPath(`/login`),
method: 'POST',
body: JSON.stringify({ email, password }),
})
},
},
}
}
import api from 'this depends on where your component is with respect to the adapter file'
// Blah blah blah
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [formSubmitted, setFormSubmitted] = useState(false)
useEffect(() => {
if(formSubmitted) {
api().login(email, password).send().then(res => res.json())
.then(res => { /*Whatever you want to do with res*/ })
.catch(error => console.log(error))
setFormSubmitted(false)
}
})
return (
// blah blah blah, do something to get email and password from user
<div>
<button onClick={() => setFormSubmitted(true)}>Submit</button>
</div>
)
openapi: "3.0.0"
title: Sample for Raghav
paths:
/login:
post:
requestBody:
content:
application/json:
schema:
type: object
properties:
email:
type: string
password:
type: string
responses:
'200':
content:
application/json:
schema:
type: object
properties:
accessToken:
type: string
password:
type: string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment