Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danidelgadoz/nodejs-restful-api-mongo
Nodejs Restful API for CRUD operation using Express and Mongoose
https://github.com/danidelgadoz/nodejs-restful-api-mongo
crud express mongodb mongoose nodejs restful
Last synced: 26 days ago
JSON representation
Nodejs Restful API for CRUD operation using Express and Mongoose
- Host: GitHub
- URL: https://github.com/danidelgadoz/nodejs-restful-api-mongo
- Owner: danidelgadoz
- Created: 2020-04-24T20:05:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-31T23:54:17.000Z (about 2 months ago)
- Last Synced: 2024-11-01T00:26:05.675Z (about 2 months ago)
- Topics: crud, express, mongodb, mongoose, nodejs, restful
- Language: JavaScript
- Homepage:
- Size: 169 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeJS Restful API
The goal of this demo is to provide an example of how to create a Restful API with Node.js using MongoDB.
## Prerequisites
Make sure you have installed the latest LTS version of [Node.js](https://nodejs.org) and [MongoDB](https://mongodb.com).
If you want to start with data run (optional):
```
mongo bookAPI < dbSeeder.js
```## Running the Application
1. Run `npm i`.
1. Run `npm run start`.
API is running on `http://localhost:3080/`.
## Tests with curl
**Get all resources**:
```
curl --location --request GET 'http://localhost:3000/books' \
--header 'apiKey: 123456'
```**Get one resource by ID**:
```
http://localhost:3000/books/614192ccc50031cdfb1e6f9f
```**Create a resource**:
```
curl --location --request POST 'http://localhost:3000/books' \
--header 'Content-Type: application/json' \
--data-raw '{
"favorite": false,
"title": "Game of thrones",
"description": "About wars and dragons",
"author": "Robert W. Martin"
}'
```**Update a resource (all fiels)**:
```
curl --location --request PUT 'http://localhost:3000/books/614192ccc50031cdfb1e6f9f' \
--header 'Content-Type: application/json' \
--data-raw '{
"favorite": false,
"title": "Game of thronesx",
"description": "About wars and dragons",
"author": "Robert W. Martin",
"posterImgPath": "https://i.picsum.photos/id/101/200/200.jpg"
}'
```**Update a resource (partial fields)**:
```
curl --location --request PATCH 'http://localhost:3000/books/614192ccc50031cdfb1e6f9f' \
--header 'Content-Type: application/json' \
--data-raw '{
"favorite": true
}'
```**Delete a reource**:
```
curl --location --request DELETE 'http://localhost:3000/books/614192ccc50031cdfb1e6f9f'
```