Skip to content

tobiasprima/Golang_MongoDB_REST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Restful API with MongoDB Database

This is hosted on https://golang-mongodb-rest.onrender.com

Quick Start

  1. Clone
git clone https://github.com/tobiasprima/Golang_MongoDB_REST.git
  1. Install Dependency
go mod tidy
  1. To test with Mongodb locally -create new .env file and add:
DATABASE_URI = {YOUR_DATABASE_URI}

-run on localhost

go run main.go
  1. Test Endpoints on postman

get products

http://localhost:8080/products

post products

http://localhost:8080/products

with body

{
    "name": "{PRODUCT_NAME}",
    "category": "{PRODUCT_CATEGORY}",
    "price": {PRODUCT_PRICE},
    "stock": {PRODUCT_STOCK}
}

patch products' price or stock

http://localhost:8080/products/{ID}   // copy ID from get/products method

with body

{
   "stock": {PRODUCT_STOCK}
}

or

{
   "price": {PRODUCT_PRICE}
}

get product by id

http://localhost:8080/products/{ID}   // copy ID from get/products method

Releases

No releases published

Packages

No packages published

Languages