/nodejs-api

A simple NodeJS API

Primary LanguageJavaScript

nodejs-api

It's a simple NodeJS API builded to follow the Rockeseat Starter NodeJS course. This API uses MongoDB as database storage.

OBS.: This API was builded on Arch Linux system.

Requirements

Packages

Getting Started

Install MongoDB via Docker

  • Assuming you alread had Docker installed and configured as well:
# download MongoDB from Docker Hub
docker pull mongo
  • Start up a database:
docker run -p 27017:27017 -d mongo

Install packages with Yarn

yarn install

Starting up the server

yarn dev

Will be running on 3001 localhost port.

Testing the API

I've been used HTTPie to test this application.

GET method

# return all records
http get :3001/api/products

# return a especific record by id
http get :3001/api/products/mongodb_id_hash

POST method

http post :3001/api/products <<<'{"title":"Product Title","description":"A sample description","url":"https://example.com"}'

PUT method

http put :3001/api/products/5ea81386864664beec2226ba <<<'{"title":"Change Title"}'

DELETE method

http delete :3001/api/products/5ea81386864664beec2226ba

Todo

  • Unit Tests
  • Integration Tests