# Clone this repository
git clone https://github.com/amrimuf/basic-crud-rest-api <folder-name>
cd <folder-name>
# Install dependencies for server
npm install
- Create .env file in the main folder
- Create DATABASE variable and assign your MongoDB Database URI value into it.
# Then, run the Express server
npm start
# Server runs on http://localhost:3000
const PostsSchema = new mongoose.Schema({
title: {
type: String,
},
author: {
type: String,
},
desc: {
type: String,
},
})
GET api/posts
GET api/posts/{id}
DELETE api/posts/{id}
POST api/posts
# Request sample
# {
# "title":"Lorem ipsum",
# "author":"Andre",
# "desc":"selamat membaca post ini"
# }
PUT api/posts/{id}
# Request sample
# {
# "title":"Updated Title",
# "author":"Andre",
# "desc":"selamat membaca post ini"
# }