Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.

Latest commit

 

History

History
33 lines (27 loc) · 586 Bytes

File metadata and controls

33 lines (27 loc) · 586 Bytes

json-server

json-server

npm install json-server
"scripts": { "server": "json-server data/names.json --port 9500" }
// GET
useEffect(() => {
  async function fetchObjects() {
    const res = await fetch(`http://localhost:9500/objects`);
  }
}, []);
// POST
async function createObjects(newObject) {
  const res = await fetch(`http://localhost:9500/objects`, {
    method: "POST",
    body: JSON.stringify(newObject),
    "Content-Type": "application/json",
  });

  const data = res.json();
}