Learning about the world of JavaScript can be incredibly daunting.
Learning NodeJS is even worse.
So I decided to write a basic web server and REST API using only Node. No express, no pug, no MongoDB, nothing.
My aim was to understand what Node had to offer on its own, and do my best to create a standard web API using just that. I figured somewhere along the way I'd understand why all of these extra modules are so nice to have.
And indeed I did.
Route parsing is a bitch using only the basic modules.
Next iteration of this project will include Express for it's excellent route parsing and middleware options.
This simple web application tracks weight measurements. It implements the following HTTP methods:
- GET
- POST
- PATCH
- DELETE
It also offers one page, the index, which shows the current weight entries.
First, clone down the repository. Next, run the following command from inside the directory:
npm start
or node server
In order to access the index page, navigate to localhost:3000
in your browser.
Use your favorite REST client, mine is Postman, to send requests to the server.
GET /api/weight
POST /api/weight
Parameters: { "date": "2017-05-17", "weight": 180 }
PATCH /api/weight/:date
Parameters: { "weight": 180 }
DELETE /api/weight/:date