RESTful API Example — with Node and Express
Set up your environment
I won’t go into detail explaining what each thing does, but you a simple Google search will tell you.
My server.js file:
The “hard” part
Let’s deal with a GET api request (gives data back to the client):
Let’s deal with a POST api request (lets the client save new data):
Let’s deal with a PUT api request (lets the client modify data):
Let’s deal with a DELETE api request (lets the client… hum.. DELETE data):
Noticed that .delete does not accept an object, rather, it accepts parameters which you can access through:
req.paramas.passedId
… passed from the URL:
'/api/delete/:passedId'
Betrayed
I feel like I betrayed you… this was too simple.
I. AM. SO. SORRY.