Popularity
0.3
Growing
Activity
7.9
Declining
3
0
0

Programming language: Go
Tags: API     Go Tools     Router     Httprouter     Go     Golang     Parameters    
Latest version: v0.1.13

go-api-router alternatives and similar packages

Based on the "Go Tools" category

Do you think we are missing an alternative of go-api-router or a related project?

Add another 'Go Tools' Package

README

go-api-router

go-api-router is a lightweight API httprouter middleware: cors, logging, and standardized error handling. Extends Julien Schmidt's httprouter package.

Go Build Status Report Codacy Badge Release standard-readme compliant GoDoc

Table of Contents

Installation

go-api-router requires a supported release of Go.

$ go get -u github.com/mrz1836/go-api-router

Package Dependencies

Documentation

You can view the generated documentation here.

Features

  • Uses the fastest router: Julien Schmidt's httprouter
  • Uses Satori's go.uuid package to guarantee unique request ids
  • Uses MrZ's go-logger for either local or remote logging via LogEntries
  • Uses MrZ's go-parameters for parsing any type of incoming parameter with ease
  • Added basic middleware support from Rileyr's middleware
  • Added Additional CORS Functionality
  • Standardized Error Responses for API Requests
  • Centralized Logging on All Requests (requesting user info & request time)
  • Custom Response Writer for Etag and Cache Support
  • GetClientIPAddress() safely detects IP addresses behind load balancers
  • GetParams() parses parameters only once
  • FilterMap() can remove any confidential parameters from logs

Examples & Tests

All unit tests and [examples](examples/examples.go) run via Travis CI and uses Go version 1.14.x. View the [deployment configuration file](.travis.yml).

Run all tests (including integration tests)

$ cd ../go-api-router
$ go test ./... -v

Run tests (excluding integration tests)

$ cd ../go-api-router
$ go test ./... -v -test.short

View and run the examples:

$ cd ../go-api-router/examples
$ go run examples.go

Benchmarks

Run the Go benchmarks:

$ cd ../go-api-router
$ go test -bench . -benchmem

Code Standards

Read more about this Go project's [code standards](CODE_STANDARDS.md).

Usage

View the [examples](examples/examples.go)

Basic implementation:

package main

import (
    "fmt"
    "net/http"

    "github.com/julienschmidt/httprouter"
    "github.com/mrz1836/go-api-router"
    "github.com/mrz1836/go-logger"
)

func main() {
    // Load the router & middleware
    router := apirouter.New()

    // Set the main index page (navigating to slash)
    router.HTTPRouter.GET("/", router.Request(index))

    // Serve the router!
    logger.Fatalln(http.ListenAndServe(":3000", router.HTTPRouter))
}

func index(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
    _, _ = fmt.Fprint(w, "This is a simple API example!")
}

Maintainers

MrZ

Contributing

This project uses Julien Schmidt's httprouter package.

This project uses Satori's go.uuid package.

This project uses Rileyr's middleware package.

View the [contributing guidelines](CONTRIBUTING.md) and follow the [code of conduct](CODE_OF_CONDUCT.md).

Support the development of this project πŸ™

Donate

License

License


*Note that all licence references and agreements mentioned in the go-api-router README section above are relevant to that project's source code only.