This is CRUD operations on MongoDB written in Golang. This is created to test the k8s operator present at (https://github.com/techierishi/k8soperator)
# Create image
docker build -t ghcr.io/techierishi/mongocrud:latest .
# Push the image to Docker Hub
docker login
docker push ghcr.io/techierishi/mongocrud:latest
Clone the repository:
git clone git@github.com:techierishi/mongocrud.git
Next, change the current directory to the repository:
cd mognocrud
docker network create crudNetwork
docker run --name mongodb -d -p 27017:27017 mongo
docker network connect crudNetwork mongodb
docker run -d -p 8060:8060 -e DBPATH="mongodb://mongodb:27017" --name mongocrud ghcr.io/techierishi/mongocrud:latest
docker network connect crudNetwork mongocrud
GET /users/:email
POST /users
PUT /users/:email
DELETE /users/:email
Send a GET
request to /users/:email
:
curl -X GET 'http://127.0.0.1:8060/users/ric@gmail.com'
Response:
{
"user": {
"id": "<user_id>",
"name": "Ric",
"email": "ric@gmail.com",
"password": "oldpass"
}
}
Send a POST
request to /users
:
curl -X POST 'http://127.0.0.1:8060/users' -H "Content-Type: application/json" -d '{"name": "Ric", "email": "ric@gmail.com", "password": "oldpass"}'
Response:
{
"user": {
"id": "<user_id>",
"name": "Ric",
"email": "ric@gmail.com",
"password": "oldpass"
}
}
Send a PUT
request to /users/:email
:
curl -X PUT 'http://127.0.0.1:8060/users/ric@gmail.com' -H "Content-Type: application/json" -d '{"password": "newpass"}'
Response:
{
"user": {
"id": "<user_id>",
"name": "Ric",
"email": "ric@gmail.com",
"password": "newpass"
}
}
Send a DELETE
request to /users/:email
:
curl -X DELETE 'http://127.0.0.1:8060/users/ric@gmail.com'
Response:
{}
{
"error": "user not found"
}