Simple NodeJS Rest API with CRUD routes. Using SQLite database
$ git clone https://github.com/lcarlesso/node-js-sqlite.git
$ cd node-js-sqlite
$ npm install
$ npm run dev
It will be running on port 4300
- Add new product:
http://localhost:4300/api/product
Sending a JSON body:
{
"name": "ExampleProductName",
"description": "Example product description",
"price": 2.00,
"currency": "EUR"
}
or an array of products:
[
{...},{...}
]
- Update a product:
http://localhost:4300/api/product
Sending a JSON body: ID is the only MANDATORY
{
"id": "1",
"name": "ExampleProductName",
"description": "Example product description",
"price": 2.00,
"currency": "EUR"
}
or an array of products:
[
{...},{...}
]
- Delete a product:
http://localhost:4300/api/product
Sending a JSON body: ID is the only MANDATORY
{
"id": "1",
"name": "ExampleProductName",
"description": "Example product description",
"price": 2.00,
"currency": "EUR"
}
or an array of products:
[
{...},{...}
]
- Load products by ID:
http://localhost:4300/api/product/id/$id
example: http://localhost:4300/api/product/id/15
- Load all products:
http://localhost:4300/api/product/
- Load products by any attribute and value:
http://localhost:4300/api/product/$attribute/$name
example:
- http://localhost:4300/api/product/price/24
- http://localhost:4300/api/product/name/Suntone $attribute = ['name', 'price', 'currency', 'description'] (this is not checked values, wrong parameters will return a DB error.)
- Load all products sorting by attribute
http://localhost:4300/api/product/sort/$attribute
example:
$attribute = ['name', 'price', 'currency', 'description'] (this is not checked values, wrong parameters will return a DB error)
- Load products sorting ASC or DESC by any attribute:
http://localhost:4300/api/product/sort/$direction/$attribute
example:
$attribute = ['name', 'price', 'currency', 'description']* $direction [ASC or DESC]C]* (the direction is checked and when wrong will return a 401 business error)
The database is already populated with 30 random values from https://www.mockaroo.com/
The Node version used was 6.9.3