Forked from MustakTalukder/Restapi laravel, and fetch from react
Last active
November 16, 2019 16:32
-
-
Save raikusy/fd9a59388e36dda855cebbd1dc306a7a to your computer and use it in GitHub Desktop.
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
const axios = require('axios'); | |
const url = 'http://todorestapi.test' | |
function ContactsList(props) { | |
const [contactList, setcontactList] = useState([]); | |
const init = async () => { | |
const response = await fetch(url + '/api/contact/all'); | |
const json = await response.json() | |
console.log(json); | |
setcontactList(json) | |
console.log(JSON.stringify(json)); | |
} | |
useEffect(() => { | |
init() | |
}, []) | |
//-------------- | |
//get from postman : http://todorestapi.test/api/contact/all | |
//-------------- | |
/* | |
Response: | |
{ | |
"status": "success", | |
"message": "Successfully get all data", | |
"data": [ | |
{ | |
"_id": "5dcfb558ccaec705b201a392", | |
"user_name": "hridoy", | |
"contact_number": "01557704794", | |
"email": "hridoy@gmail.com", | |
"address": "sylhet", | |
"updated_at": "2019-11-16 08:37:44", | |
"created_at": "2019-11-16 08:37:44" | |
}, | |
{ | |
"_id": "5dcfe83eccaec705b201a393", | |
"user_name": "hridoy", | |
"contact_number": "01557704794", | |
"email": "hridoy@gmail.com", | |
"address": "sylhet", | |
"updated_at": "2019-11-16 12:14:53", | |
"created_at": "2019-11-16 12:14:53" | |
}, | |
{ | |
"_id": "5dcfe842ccaec705b201a394", | |
"user_name": "hridoy2", | |
"contact_number": "01557704794", | |
"email": "hridoy@gmail.com", | |
"address": "sylhet", | |
"updated_at": "2019-11-16 12:14:58", | |
"created_at": "2019-11-16 12:14:58" | |
} | |
] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment