modulepackage
0.0.0-20240514030016-c0e126ee7a6e
Repository: https://github.com/mikaojk/go-crud-rest-api.git
Documentation: pkg.go.dev
# README
go-crud-rest-api
Technologies used:
- Go
- Docker
Prerequisites
go
Make sure you have the go installed using this command:
go version
Docker
Make sure you have docker installed using this command:
docker --version
Curl
Make sure you have curl installed using this command:
curl --version
Build the code
go build .
Run the code
OBS: Need a Postgres DB up and running
go run .
Running the application locally
Create docker image of app
Creating a docker image should be as simple as
docker build -t goapp .
๐ Run the Postgres container
docker-compose up -d db
๐๏ธ Build the go app image
docker compose build
๐ Run the Go Container
docker compose up goapp
๐งช Test the applications endpoints
Request to get the all the users:
curl --location --request GET 'http://localhost:8080/users'
Example of a response:
[ { "id": 1, "name": "aaa", "email": "aaa@mail" }, { "id": 2, "name": "bbb", "email": "bbb@mail" } ]
Request to create a new user
curl --location --request POST 'http://localhost:8080/users' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "aaa","email": "aaa@mail"}'
Request to get one specific user:
curl --location --request GET 'http://localhost:8080/users/2'
Example of a response:
{ "name": "new", "email": "new@mail" }
Request to update a user
curl --location --request PUT 'http://localhost:8080/users/2' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "new","email": "new@mail"}'
Request to delete a user
curl --location --request DELETE 'http://localhost:8080/users/3'
Contact
This project is maintained by MikAoJk
# Packages
No description provided by the author