Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FETCH API to POST a new Item #29

Open
3 tasks
marjoriekohn opened this issue Apr 15, 2023 · 0 comments
Open
3 tasks

FETCH API to POST a new Item #29

marjoriekohn opened this issue Apr 15, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@marjoriekohn
Copy link
Member

  • In js/ItemsController.js, implement a new function called save that will POST the new item's data using the fetch function:

    save(name, description, imageUrl){ const data = { name, description, imageUrl }; fetch('http://localhost:8080/item', { method: 'POST', // or 'PUT' headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); });}

  • Modify the save method of the ItemsController.java to avoid the CORS mechanism

    @CrossOrigin @PostMapping public Item save( @RequestBody ItemDto itemDto ) { return itemService.save( new Item( itemDto ) );}

  • Add a call to the save function inside the scope of addItem function (you could call it after the items are stored on the localStorage).

@marjoriekohn marjoriekohn moved this from 🆕 New to 📋 Backlog in Cheese Crave's Project Planning Apr 17, 2023
@marjoriekohn marjoriekohn added the enhancement New feature or request label Apr 18, 2023
@marjoriekohn marjoriekohn added this to the Front-End Complete milestone Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant