Skip to content

⬡ An Go REST API following the SOLID principles and Clean Architecture.

Notifications You must be signed in to change notification settings

LuisCusihuaman/go-hexagonal-http-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Hexagonal RESTful API

Hexagonal architecture, cqrs, event modeling and testing in golang

Based on the projects of the API HTTP en Go aplicando Arquitectura Hexagonal

arquitecture

🔨 Requirements

🚀 Environment setup

# download project
git clone https://github.com/LuisCusihuaman/go-hexagonal-http-api

cd go-hexagonal-http-api

# run api with docker compose
docker-compose up -d --build

🏎️ Getting Started

At this time, you have a RESTful API server running at http://localhost:8080/. It provides the following endpoints:

  • GET /health: a healthcheck service provided for health checking purpose (needed when implementing a server cluster)
  • POST /courses: creates a new course

Try the URL http://localhost:8080/health in a browser, and you should see something like "everything is ok!" displayed.

If you have cURL or some API client tools (e.g. Postman), you may try the following more complex scenarios:

# healthcheck service provided by: GET /health
curl -X GET --location "http://localhost:8080/health" \
    -H "Accept: application/json"
# should return a healthcheck text: 'everything is ok!'

# creates a new course via: POST /courses
curl -sw '%{http_code}' -X POST --location "http://localhost:8080/courses" \
    -H "Content-Type: application/json" \
    -d "{
          \"id\": \"11d365ab-062f-4dff-9277-8474c50d8e12\",
          \"name\": \"Golang course\",
          \"duration\": \"1 month\"
        }"
# should return a http status code: 201

Connect to database

docker-compose exec mysql mysql -u user -ppassword -D backoffice

SELECT * FROM courses;

Show logs

docker-compose logs -f mooc-api

Tests

To execute all tests, just run:

go test ./... 

About

⬡ An Go REST API following the SOLID principles and Clean Architecture.

Topics

Resources

Stars

Watchers

Forks