Skip to content

Commit

Permalink
add notes to explain difference between sending info in the body of t…
Browse files Browse the repository at this point in the history
…he json payload and as params in the URL b00tc4mp#430
  • Loading branch information
juditta99 committed May 16, 2024
1 parent 07dae09 commit 1baba0e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import logic from '../logic/index.js'
import { errors } from 'shared'
const { NotFoundError, ContentError } = errors

//when you send a request to an endpoint, you can include information in the request in several ways, primarily in the body of the JSON payload or as URL parameters. In the body of the JSON payload: is typically used with POST, PUT, PATCH, and sometimes DELETE requests. The body of the request contains the data you want to send to the server, often in JSON format. As URL params: This method is typically used with GET requests to filter or search resources. It can also be used with DELETE requests to specify which resource to delete by its ID directly in the URL. In this case we use params because all we are sending is the id of the resource to be deleted:

export default (req, res) => {
const { id } = req.params
try {
Expand Down
14 changes: 1 addition & 13 deletions staff/judy-grayland/project/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,9 @@ mongoose

server.get('/resources', retrieveResourcesHandler)

// the :id is dynamic. we pass the id as params to specify which resource needs to be deleted
server.delete('/resources/:id', deleteResourceHandler)

// declaring endpoint for categories path
// server.get('/categories', (req, res) => {
// Category.find()
// .then((categories) => {
// console.log(categories)
// res.json(categories)
// })
// .catch((error) => {
// console.log('Error retrieving data from MongoDB', error)
// res.status(500).json({ error: 'Internal server error' })
// })
// })

server.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}`)
})
Expand Down

0 comments on commit 1baba0e

Please sign in to comment.