Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/putukrisna6/golang-api
RESTful Go API with Docker
https://github.com/putukrisna6/golang-api
api caching docker docker-compose gin golang gorm jwt mysql portainer-ce redis rest-api
Last synced: 2 months ago
JSON representation
RESTful Go API with Docker
- Host: GitHub
- URL: https://github.com/putukrisna6/golang-api
- Owner: putukrisna6
- License: mit
- Created: 2022-03-04T18:30:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-27T06:35:18.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T17:44:56.378Z (7 months ago)
- Topics: api, caching, docker, docker-compose, gin, golang, gorm, jwt, mysql, portainer-ce, redis, rest-api
- Language: Go
- Homepage: https://simple-rest-go.herokuapp.com/
- Size: 114 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple REST API Go App
## Features:
- Gin for the web framework
- Gorm for ORM
- jwt-go for authentication
- Redis for caching
- MariaDB for main db
- phpMyAdmin for db management
- Portainer for container management## How to use:
- Clone the repo
- Setup your .env file
- Run `docker-compose up -d`## Misc info:
### phpMyAdmin
- access via `http://localhost:8085/` or through the "Open in Browser" in Docker Desktop
- by default: server is `db`, username is `root`, and password is `test`. configurable within `docker-compose.yml`
### Portainer
- access via `http://localhost:9000/`
- feel free to set the password and username when running it for the first time
### Testing
- open your browser and go to `http://localhost:8080/`, if all is fine you would be greeted by `Hello, World`
- use Postman or similar tools and set the url to `http://localhost:8080/`
- do not forget to set the `Authorization` key within `Headers` on your requests on some routes protected by the jwt middleware
- available routes:
- POST /api/auth/login
- POST /api/auth/register
- GET /api/users/profile
- PUT /api/users
- GET /api/books
- POST /api/books
- GET /api/books/:id
- PUT /api/books
- DELETE /api/books/:id
- GET /api/receipts/all
- POST /api/receipts
- GET /api/receipts/:id
- PUT /api/receipts
- DELETE /api/receipts/:id
- GET /- some jquery request I used to test the APIs from another domain
```js
$.ajax({
url: "http://localhost:8080/api/receipts/all"
})
``````js
$.ajax({
url: "http://localhost:8080/api/receipts/1"
})
```
```js
$.ajax({
type: 'POST',
url: "http://localhost:8080/api/receipts",
data: {"amount":3,"total":67},
dataType: "json",
success: function(resultData) { alert("Save Complete") }
});
```
```js
$.ajax({
type: 'PUT',
url: "http://localhost:8080/api/receipts",
data: {"id":4,"amount":323,"total":6723.2},
dataType: "json",
success: function(resultData) { alert("Update Complete") }
});
```
```js
$.ajax({
type: 'DELETE',
url: "http://localhost:8080/api/receipts/4",
dataType: "json",
success: function(resultData) { alert("Delete Complete") }
});
```