Web API demo with MySQL support
git clone [email protected]:norberteder/golang_webapidemo.git
cd golang_webapidemo
docker-compose up -d
Create a new contact
http post http://localhost:8081/api/1/contacts firstName=Norbert lastName=Eder [email protected]
Get all contacts
http get http://localhost:8081/api/1/contacts
Expected result:
[
{
"email": "[email protected]",
"firstName": "Norbert",
"id": 1,
"lastName": "Eder"
}
]
(Sample API calls use HTTPie)
If the http calls don't work it might caused by the crashed app container. This can happen if the database is starting to slow and is not available when the app container is trying to access it on startup (the app should use some retry for database connections).
To validate this, just run docker logs golangwebapidemo_app_1
.
The result might be:
2018/04/13 20:15:28 Initializing database ...
2018/04/13 20:15:28 dial tcp 172.31.0.2:3306: connect: connection refused
panic: dial tcp 172.31.0.2:3306: connect: connection refused
If this is the result, just wait a few seconds and re-run docker-compose up -d