https://github.com/dedidot/simple-api-golang
Golang simple api with Mux and Gorm
https://github.com/dedidot/simple-api-golang
go golang gorm restful-api simple-api tutorial
Last synced: 10 months ago
JSON representation
Golang simple api with Mux and Gorm
- Host: GitHub
- URL: https://github.com/dedidot/simple-api-golang
- Owner: dedidot
- Created: 2018-01-07T05:19:34.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-13T04:13:17.000Z (about 8 years ago)
- Last Synced: 2025-03-25T11:04:02.536Z (11 months ago)
- Topics: go, golang, gorm, restful-api, simple-api, tutorial
- Language: Go
- Size: 4.88 KB
- Stars: 10
- Watchers: 1
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Api with Go
It is a just simple RESTful API with Go using:
1. **gorilla/mux**
2. **gorm**
## Installation & Run
```bash
# Download this project
$ go get github.com/dedidot/simple-api-golang
# Download Mux Router
$ go get github.com/gorilla/mux
# Download GORM
$ go get github.com/jinzhu/gorm
# Download stringer / generate random id
$ go get github.com/dedidot/generate/stringer
```
Setting DB in config/database.go
```go
func GetConfig() *Config {
return &Config{
DB: &DBConfig{
Dialect: "mysql",
Username: "root",
Password: "",
Name: "testinger",
Charset: "utf8",
},
}
}
```
```bash
# Build and Run
cd simple-api-golang
go build
./simple-api-golang
# API Endpoint : http://127.0.0.1:8000
```
## Structure
```
├── app
│ ├── routes.go // Router
│ ├── controllers // Our API core handlers
│ │ ├── ActionPostBook.go
│ │ ├── ActionViewBook.go
│ └── models
│ | └── book.go // APi Model
| └── utils
| └── utils.go // generate id
├── config
│ └── database.go // Configuration
├── migrate
| └── book.go // Models for our application
└── main.go
```
## API
#### /book
* `GET` : Get all book
* `POST` : Create a new book
#### /book/:codes
* `GET` : Get a book
* `PUT` : Update a book
* `DELETE` : Delete a book
#Post Params
```
{
"author": "Op Super John Doe Bilw",
"name": "Implementation Golang",
"category": "Knowledge"
}
```
```bash
# Inspired By
github.com/mingrammer/go-todo-rest-api-example
```