Guest User

Untitled

a guest
Jun 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. app.get("/users", (req, res) => {
  2. console.log("a get request");
  3. var tryFetch = { myString: "I am working fetch" };
  4. res.json(tryFetch);
  5. });
  6.  
  7. class Example extends React.Component {
  8. async componentDidMount() {
  9. console.log("mounting...");
  10. const response = await fetch("/users");
  11. console.log(response, "res");
  12. const responseJson = await response.json();
  13. console.log(responseJson, "this is the data....");
  14. }
  15.  
  16. app.get("/users", (req, res) => {
  17. console.log("a get request");
  18. var getData = await fetch("https://jsonplaceholder.typicode.com/users");
  19. var response = await getData.json();
  20. console.log(response, "the response");
  21. res.send(json);
  22. });
Add Comment
Please, Sign In to add comment