All Projects β†’ bahlo β†’ Goat

bahlo / Goat

Licence: mit
[DEPRECATED] 🐐 A minimalistic JSON API server in Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Goat

Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+24488.82%)
Mutual labels:  rest, json, framework
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (+116.15%)
Mutual labels:  rest, json, framework
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+494.41%)
Mutual labels:  rest, middleware, json
Zerocode
A community-developed, free, open source, microservices API automation and load testing framework built using JUnit core runners for Http REST, SOAP, Security, Database, Kafka and much more. Zerocode Open Source enables you to create, change, orchestrate and maintain your automated test cases declaratively with absolute ease.
Stars: ✭ 482 (+199.38%)
Mutual labels:  rest, json, framework
Min
A minimalistic web framework with route grouping and middleware chaining
Stars: ✭ 95 (-40.99%)
Mutual labels:  rest, middleware, framework
Fetch Plus
πŸ• Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (-27.95%)
Mutual labels:  rest, json
Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (-27.33%)
Mutual labels:  json, framework
Finch
Scala combinator library for building Finagle HTTP services
Stars: ✭ 1,552 (+863.98%)
Mutual labels:  rest, json
Httpexpect
End-to-end HTTP and REST API testing for Go.
Stars: ✭ 1,821 (+1031.06%)
Mutual labels:  rest, json
Psx
PHP REST API Framework
Stars: ✭ 108 (-32.92%)
Mutual labels:  rest, framework
Resource Router Middleware
🚴 Express REST resources as middleware mountable anywhere
Stars: ✭ 124 (-22.98%)
Mutual labels:  rest, middleware
Aping
angular module to get and display data by adding html-attributes
Stars: ✭ 135 (-16.15%)
Mutual labels:  rest, json
Marklogic Data Hub
The MarkLogic Data Hub: documentation ==>
Stars: ✭ 113 (-29.81%)
Mutual labels:  json, framework
Json Serverless
Transform a JSON file into a serverless REST API in AWS cloud
Stars: ✭ 108 (-32.92%)
Mutual labels:  rest, json
Narration
The Narration PHP Framework - Empowering everyone to build reliable and loosely coupled web apps.
Stars: ✭ 119 (-26.09%)
Mutual labels:  rest, framework
Persianjsonplaceholder
Persian fake REST/GraphQL API for testing and prototyping.
Stars: ✭ 110 (-31.68%)
Mutual labels:  rest, json
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-21.74%)
Mutual labels:  middleware, framework
Smoke
πŸ’¨ Simple yet powerful file-based mock server with recording abilities
Stars: ✭ 142 (-11.8%)
Mutual labels:  rest, json
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-13.66%)
Mutual labels:  middleware, framework
Restclient.net
.NET REST Client Framework for all platforms
Stars: ✭ 143 (-11.18%)
Mutual labels:  rest, json

⚠️ DEPRECATED ⚠️

This project is no longer maintained, please use something like gorilla/mux or echo.


Goat GoDoc Build Status Coverage Status

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.

Contents

Usage

Parameters

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")
}

Subrouters

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")
}

Indices

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

Middleware

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")
}

Wrapping middleware

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")
}

Philosophy

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).

Feedback

If you have problems, feel free to create an issue or drop me an email at [email protected]!

Credits

Thanks to Julien Schmidt for the amazing httprouter used in this project.

License

This project is licensed unter MIT, for more information look into the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].