https://github.com/melihmucuk/monkeys
tiny rest framework for golang
https://github.com/melihmucuk/monkeys
framework golang httprouter rest
Last synced: 10 months ago
JSON representation
tiny rest framework for golang
- Host: GitHub
- URL: https://github.com/melihmucuk/monkeys
- Owner: melihmucuk
- License: mit
- Created: 2018-02-12T22:00:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-14T09:35:59.000Z (about 8 years ago)
- Last Synced: 2025-03-20T22:50:34.464Z (about 1 year ago)
- Topics: framework, golang, httprouter, rest
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# monkeys
tiny rest framework for golang
## Install
```
go get -u github.com/melihmucuk/monkeys
```
## Usage
```go
package main
import (
"log"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/melihmucuk/monkeys"
)
type ItemController struct{}
func (ic ItemController) Get() *monkeys.Response {
items := []string{"item1", "item2"}
data := map[string][]string{"items": items}
return &monkeys.Response{StatusCode: 200, Data: data}
}
func (ic ItemController) GetByID(ID string) *monkeys.Response {
return &monkeys.Response{StatusCode: 200, Data: ID}
}
func (ic ItemController) Post(body monkeys.Request) *monkeys.Response {
return &monkeys.Response{StatusCode: 200, Data: body}
}
type PingController struct{}
func (pc PingController) Get() *monkeys.Response {
data := make(map[string]interface{})
data["respond"] = "pong"
return &monkeys.Response{StatusCode: 200, Data: data}
}
// HostMiddleware custom middleware
func HostMiddleware(next httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
log.Printf("%s", r.Host)
if r.Host == "localhost:5000" {
next(w, r, p)
return
}
monkeys.ErrorResponse(http.StatusForbidden, 4, "Host not allowed!", w)
}
}
func main() {
api := monkeys.NewAPI()
api.Use(monkeys.Logger)
api.Use(HostMiddleware)
api.NewEndpointGroup("/item", ItemController{})
api.NewEndpoint("GET", "/ping", PingController{})
api.Start(5000)
}
```
## TODO
- [ ] Integrate all http methods (PUT, PATCH etc.)
- [ ] Create documentation
- [ ] Write tests
- [ ] Add benchmark result
- [ ] Create built-in middleware for CORS