Skip to content

Instantly share code, notes, and snippets.

@raikusy
Forked from MustakTalukder/Restapi laravel, and fetch from react
Last active November 16, 2019 16:32
Show Gist options
  • Save raikusy/fd9a59388e36dda855cebbd1dc306a7a to your computer and use it in GitHub Desktop.
Save raikusy/fd9a59388e36dda855cebbd1dc306a7a to your computer and use it in GitHub Desktop.
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