Last active
November 4, 2020 13:42
-
-
Save akshay-nm/42eec6ca6e6096158addf2d91c951245 to your computer and use it in GitHub Desktop.
Example for raghav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }), | |
}) | |
}, | |
}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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