JSON-SERVER (1)
JSON-SERVER (1)
db.json
{
"user": [
{
"name": "manoj",
"city": "dng"
},
{
"id": "d096",
"name": "bob",
"city": "delhi"
}
]
}
// function App() {
// useEffect(()=>{
// axios.get("http://localhost:3000/user")
// .then((res)=>{
// console.log(res.data)
// })
// },[])
// return (
// <div>
// </div>
// )
// }
// function App() {
// useEffect(()=>{
// axios.get("http://localhost:3000/user/id")
// .then((res)=>{
// console.log(res.data)
// })
// },[])
// return (
// <div>
// </div>
// )
// }
// function App() {
// useEffect(() => {
// axios.get("http://localhost:3000/user", { params: { name: "manoj" } })
// .then((res) => {
// console.log(res.data)
// })
// .catch((err) => {
// console.error(err)
// })
// }, [])
// return (
// <div>
// {/* You can render response data here */}
// </div>
// )
// }
function App() {
useEffect(() => {
axios.get("http://localhost:3000/user", { params: { name:
"manoj" ,city:"dng"} })
.then((res) => {
console.log(res.data)
})
.catch((err) => {
console.error(err)
})
}, [])
return (
<div>
{/* You can render response data here */}
</div>
)
}
// http://localhost:3000/user?name=manoj&city=dng or
"http://localhost:3000/user", { params: { name: "manoj" ,city:"dng"} }
===================================================================================
================================
http://localhost:3000/user?name=manoj&city=dng
function UserComponent() {
const location = useLocation();
return (
<div>
<h2>User Details</h2>
<p>Name: {name}</p>
<p>City: {city}</p>
</div>
);
}