Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmedwaleedmalik/chuck-norris-api
Golang REST API with MYSQL for persistence
https://github.com/ahmedwaleedmalik/chuck-norris-api
Last synced: 23 days ago
JSON representation
Golang REST API with MYSQL for persistence
- Host: GitHub
- URL: https://github.com/ahmedwaleedmalik/chuck-norris-api
- Owner: ahmedwaleedmalik
- License: apache-2.0
- Created: 2021-08-19T15:30:18.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T14:27:56.000Z (11 months ago)
- Last Synced: 2024-06-21T07:43:41.255Z (5 months ago)
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chuck-norris-api
Golang REST API with MYSQL for persistence
## Application
This is a sample application using the [chuck-norris-api](https://api.chucknorris.io/) package. This application is a demonstration of a basic REST API in Golang which interacts with a MYSQL database as a persistent storage back-end.
### Dependencies
1. `net/http` stdlib is used for the http server and routing for the sake of simplicity.
2. `GORM`, an ORM library for Golang, is used for interacting with the MYSQL database.### Endpoints
- [x] `GET /banter` returns a list of jokes
- [x] `GET /health/live` checks for the liveness of application
- [x] `GET /health/ready` checks for the readiness of application to accept traffic. Ensures that all backing services are up and running.### Configuration
The following tables lists the configurable parameters for the application and their default values:
| Parameter | Default | Description |
| -------------- | ----------- | --------------------------------------- |
| `SQL_HOST` | `localhost` | Host name for SQL database |
| `SQL_PORT` | `3036` | Access port for SQL |
| `SQL_USERNAME` | `root` | Username for accessing the SQL database |
| `SQL_PASSWORD` | | Password for accessing the SQL database |
| `SQL_DATABASE` | `banter` | Database name |**NOTE:** The `SQL_PASSWORD` parameter has no default value for security reasons.
### Logging strategy
Following [12 factor app](https://12factor.net) methodologies, we will rely on `stdout` for logs of this application.
## Deployment
Deployment is divided into the following components:
- Simple storage server i.e. `MYSQL`
- REST API server that exposes `/banter` endpoint to retrieve list of all jokes from the storage server
- Reverse proxy that serves the REST API serverAs a best practice, we are not using default port `3306` for the SQL server and instead relying on `3313` as the serving port.
### Requirements
1. [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)
2. [minikube](https://minikube.sigs.k8s.io/docs/start/)### Deploy
For end-to-end deployment, run `make release-and-deploy` this command will:
- Build image against latest code
- Push image to remote registry
- Update image reference in [deployment](./deploy/api/deployment.yaml)
- Run deployment script, which performs the following action
- Ensure that kubectl and minikube are installed. This script will install them automatically on "linux-gnu" OS.
- Start a minikube cluster
- Deploy nginx-ingress
- Deploy MYSQL
- Deploy the REST API server
- Print out the URL to access the applicationElse, you can run `make deploy` to just deploy the application without creating a new release(build, push docker image)
## Local Development
### Requirements
- golang 1.16
### Execution
- Run `docker-compose up -d` to start the local development environment i.e. mysql; the backing service
- Run `SQL_PASSWORD=root make run` to run the application that serves on port 8080