REST API with Golang and MongoDB
Install all required dependencies:
go get -u github.com/gin-gonic/gin go.mongodb.org/mongo-driver/mongo github.com/joho/godotenv github.com/go-playground/validator/v10
Create user:
curl --location --request POST 'http://localhost:8080/users/' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Marco Reus",
"location": "Sweden",
"title": "Software Engineer"
}'
Get user by id:
curl --location --request GET 'http://localhost:8080/users/63c03f81cfba3a189540572b'
Update user info:
curl --location --request PUT 'http://localhost:8080/users/63c03f81cfba3a189540572b' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Marco Reus!",
"location": "Sweden",
"title": "Go Software Engineer"
}'
Delete user:
curl --location --request DELETE 'http://localhost:8080/users/63c03f81cfba3a189540572b'
github.com/gin-gonic/gin
is a framework for building web applications.
go.mongodb.org/mongo-driver/mongo
is a driver for connecting to MongoDB.
github.com/joho/godotenv
is a library for managing environment variables.
github.com/go-playground/validator/v10
is a library for validating structs and fields.
- Gin-gonic - framework for building web applications.
- MongoDB Go Driver - driver for connecting to MongoDB.
- Go Validator - library for managing environment variables.
- Go Environment Loader - library for validating structs and fields.
- Golang dto-mapper - l