This is an API built with the Go programming language, the Gin web framework and Kafka to stream events. The purpose of this project is to learn the basic concepts of building a RESTful API using Go, Gin and Kafka Events in SAGA pattern.
To run this project, you need to have GO installed on your machine. You can download it from the official Go website. Also, you need to have Docker installed to run Kafka, Zookeeper and the services that are part of the SAGA pattern implementation.
-
Clone the repository:
git clone https://github.com/MrRique15/go_rest_api.git
-
Change into the project directory:
cd go_rest_api
-
Change MongoDB URI and MongoDB Database env in docker-compose.yml
-
build and Start Docker containers:
docker-compose up --build
The SAGA pattern is a way to manage distributed transactions. It is a sequence of local transactions where each transaction updates the database and publishes a message or event to trigger the next transaction in the sequence. If one of the transactions fails, the SAGA pattern uses compensating transactions to undo the changes made by the preceding transactions.
You can check the SAGA pattern implementation in this project by checking the inventory_service and main_api folders. Also, you can check the Diagram of the SAGA pattern implementation in the image below:
After running Docker containers, you can access the API in the following URL: http://localhost:8080
.
All the requests made to this URL will be handled by the API Gateway, which will publish events to Kafka topics when needed, to trigger the services that are part of the SAGA pattern implementation.
To check the API endpoints, you can access the routes documentation.
To test the API Gateway application, execute the following command:
cd main_api
go test -v
It will run all tests that has been set in files like *_test.go
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.