Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Fig | 258 | 8 | 5 days ago | 2 | January 03, 2022 | 2 | apache-2.0 | Go | ||
A minimalist Go configuration library | ||||||||||
Tiny Json Http | 165 | 191 | 40 | a month ago | 43 | March 15, 2022 | 5 | JavaScript | ||
:anchor: Minimalist HTTP client for JSON payloads. | ||||||||||
Goat | 160 | 1 | 5 years ago | 8 | March 21, 2016 | 4 | mit | Go | ||
[DEPRECATED] :goat: A minimalistic JSON API server in Go | ||||||||||
Fastjsonparser | 152 | 20 days ago | 8 | other | C# | |||||
A minimalistic and fast JSON parser/deserializer, for full .NET | ||||||||||
Gauth | 79 | 3 years ago | May 31, 2021 | mit | Go | |||||
Example for getting JWT tokens in go | ||||||||||
Microdb | 72 | 6 | 6 years ago | 2 | August 27, 2016 | 3 | other | PHP | ||
MicroDB is a minimalistic file-based JSON object database written in PHP. | ||||||||||
Bldr | 60 | 9 years ago | 9 | mit | Ruby | |||||
Minimalist JSON templating DSL. | ||||||||||
Npm Launch | 38 | 6 years ago | 7 | September 08, 2016 | 6 | mit | JavaScript | |||
🚀 Minimalistic task runner on steroids! | ||||||||||
Nicholas | 33 | 2 years ago | 4 | mit | PHP | |||||
✨ Ultra-lightweight, no-fuss, flat-file & nearly-headless blogging system | ||||||||||
Json Crate | 27 | 6 years ago | 3 | August 30, 2017 | mit | JavaScript | ||||
📦 json-crate: a minimalistic promise-based json database |
This project is no longer maintained, please use something like gorilla/mux or echo.
Goat is a minimalistic REST API server in Go. You can pronounce it like the goat, or go-at. Depends on how you like goats.
You can use named parameters and access them through goat.Params
,
wich you can treat as any map[string]string
.
package main
import (
"net/http"
"github.com/bahlo/goat"
)
func helloHandler(w http.ResponseWriter, r *http.Request, p goat.Params) {
goat.WriteJSON(w, map[string]string{
"hello": p["name"],
})
}
func main() {
r := goat.New()
r.Get("/hello/:name", "hello_url", helloHandler)
r.Run(":8080")
}
You can create subrouters to simplify your code
func main() {
r := goat.New()
r.Get("/hello/:name", "hello_url", helloHandler)
sr := r.Subrouter("/user")
{
sr.Post("/login", "user_login_url", loginHandler)
sr.Get("/logout", "user_logout_url", logoutHandler)
}
r.Run(":8080")
}
Every route can have a description (like user_login_url
). These can be used
to automagically generate an API index (like this).
If you want to hide specific methods, just provide an empty string.
func main() {
r := goat.New()
r.Get("/", "", r.IndexHandler)
r.Get("/hello/:name", "hello_url", helloHandler)
sr := r.Subrouter("/user")
{
sr.Post("/login", "user_login_url", loginHandler)
sr.Get("/logout", "user_logout_url", logoutHandler)
}
r.Run(":8080")
}
The above example would return the following response on /
:
{
"hello_url": "/hello/:name",
"user_logout_url": "/user/logout"
}
Note: Indices are only supported for GET
requests. Open an issue, if you
want them on other methods, too
You can easily include any middleware you like. A great guide to middleware is found here. Important is, that it's in the following format:
func(http.Handler) http.Handler
Example:
func main() {
r := goat.New()
r.Get("/hello/:name", "hello_url", helloHandler)
r.Use(loggerMiddleware, gzipMiddleware)
r.Run(":8080")
}
Sometimes middleware isn't in the required format, so you have to build a
wrapper around it. This example shows a wrapper around
handlers.CombinedLoggingHandler
from the
Gorilla handlers:
func loggerMiddleware(h http.Handler) http.Handler {
// Create logfile (you should check for errors)
f, _ := os.Create("api.log")
return handlers.CombinedLoggingHandler(f, h)
}
You can now safely use the middleware in Goat:
func main() {
r := goat.New()
r.Get("/hello/:name", "hello_url", helloHandler)
r.Use(loggerMiddleware)
r.Run(":8080")
}
I wanted to create a small, fast and reliable REST API server, which supports quick JSON and error output, good rooting and easy-to-use middleware.
I have split the files after responsibility to make it easy for everyone to
dive in (start with goat.go
).
If you have problems, feel free to create an issue or drop me an email at [email protected]!
Thanks to Julien Schmidt for the amazing httprouter used in this project.
This project is licensed unter MIT, for more information look into the LICENSE file.