Skip to content
This repository was archived by the owner on Mar 11, 2023. It is now read-only.
/ gap Public archive

Custom generic HTTP handler providing automatic JSON decoding/encoding of HTTP request/response to your concrete types

License

Notifications You must be signed in to change notification settings

ectobit/gap

Repository files navigation

gap

Build Status Go Coverage License

Custom generic HTTP handler providing automatic JSON decoding/encoding of HTTP request/response to your concrete types. gap.Wrap allows to use these custom handlers just as idiomatic Go't HTTP handler functions.

Problem description

Standard HTTP handler functions in Go have signature func(http.ResponseWriter, *http.Request) which doesn't allow an easy RESTful API implementation. On each request you have to parse the request body using JSON decoder, process the request and return the response body by using JSON encoder. This means lot of code repetitions or at least not elegant and clean code.

Solution

Using benefits of Go's generics, it's possible now to have generic requests and responses and hide the JSON encoding and decoding in a wrapper which provides the standard HTTP handler functions at the end. This way you can focus to your business logic and not to boring parts like encoding, decoding and many errors that may happen. This projects provides HTTP handler function with signature func(*gap.Request[I]) *gap.Response[O], where I is your request body type and O is response body type. For GET requests request body type is simply struct{}.

Contribution

  • make test runs unit tests
  • make test-cov displays test coverage

About

Custom generic HTTP handler providing automatic JSON decoding/encoding of HTTP request/response to your concrete types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •