REST API for a User Information application in which we create new users, view them, update & delete their information. Here I used a NoSQL database MongoDB for storing the data.
https://go-userapi-rest.herokuapp.com/swagger/index.html
-
Go
1.18
Rest of requirements are pulled by go itself. Database is already configured but can be changed.
-
Clone the repo
https://github.com/Guleri24/go-userapi-rest.git
-
Open
go-userapi-rest
cd go-userapi-rest
-
Install project dependencies
go get ./...
-
Optional: Swagger Docs
swag init
-
Run
go run main.go
POST
/user
(Creates a new user)
name type data type description Body required object (JSON) User obj
curl -X 'POST' 'https://go-userapi-rest.herokuapp.com/api/v1/user' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"address": "Guler, Himachal Pradesh","description": "Student@NITH","dob": "24-12-2000","name": "Guleri"}'
GET
/user/{id}
(Get user by given ID)
name type data type description id required string User ID
curl -X 'GET' 'https://go-userapi-rest.herokuapp.com/api/v1/user/63023e32606a56bdd637c202' -H 'accept: application/json'
DELETE
/user/{id}
(Deletes a user by given ID)
name type data type description id required string User ID
curl -X 'DELETE' 'https://go-userapi-rest.herokuapp.com/api/v1/user/63023e32606a56bdd637c202' -H 'accept: application/json'
PATCH
/user/{id}
(Updates a user by given ID)
name type data type description id required string User Id Body required object(json) User obj
curl -X 'PATCH' 'https://go-userapi-rest.herokuapp.com/api/v1/user/63000c7aa8079cb65b7478e7' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"address": "Hostel@DBH","description": "Student@NITH","dob": "24-12-2000","name": "Guleri24"}'