All Projects → alexisvisco → kcd

alexisvisco / kcd

Licence: Apache-2.0 License
KCD lets you focus on what matters: coding.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to kcd

Giraffe.Razor
Razor view engine http handlers for Giraffe web applications.
Stars: ✭ 27 (-38.64%)
Mutual labels:  http-handler
handlers
Go's HTTP handlers I use in my projects
Stars: ✭ 53 (+20.45%)
Mutual labels:  http-handler
rux
⚡ Rux is an simple and fast web framework. support route group, param route binding, middleware, compatible http.Handler interface. 简单且快速的 Go api/web 框架,支持路由分组,路由参数绑定,中间件,兼容 http.Handler 接口
Stars: ✭ 81 (+84.09%)
Mutual labels:  http-handler
Giraffe
Giraffe is an F# micro web framework for building rich web applications. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware. Giraffe applications are composed of so called HttpHandler functions which can be thought of a mixture of Suave's WebParts and ASP.NET Core's middleware.
Stars: ✭ 1,703 (+3770.45%)
Mutual labels:  http-handler
Giraffe.TokenRouter
Alternative routing API for Giraffe web applications which is aimed at maximum performance.
Stars: ✭ 21 (-52.27%)
Mutual labels:  http-handler

kcd logo

kcd is passing lint and tests kcd has a a+ report Coverage Status documentation


comparaison between a code with and without kcd

🌠 KCD

KCD is a grandiose REST helper that wrap your shiny handler into a classic http handler. It manages all you want for building REST services.

This library is opinionated by default but customizable which mean it uses some other libraries like Chi, Logrus... KCD is modular so each pieces of the code that rely on a specific library can be changed.

💪 Example

🚀 QuickStart

package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi"
	"github.com/go-chi/chi/middleware"

	"github.com/alexisvisco/kcd"
)

func main() {
	r := chi.NewRouter()
	r.Use(middleware.RequestID)

	// You can configure kcd with kcd.Config

	r.Get("/{name}", kcd.Handler(YourHttpHandler, http.StatusOK))
	//                       ^ Here the magic happen this is the only thing you need
	//                         to do. Adding kcd.Handler(your handler)
	_ = http.ListenAndServe(":3000", r)
}

// CreateCustomerInput is an example of input for an http request.
type CreateCustomerInput struct {
	Name     string   `path:"name"`                 // you can extract value from: 'path', 'query', 'header', 'ctx'
	Emails   []string `query:"emails" exploder:","` // exploder split value with the characters specified
	Subject  string   `json:"body"`                 // it also works with json body
}

// CreateCustomerOutput is the output type of the http request.
type CreateCustomerOutput struct {
	Name string `json:"name"`
}

// YourHttpHandler is your http handler but in a shiny version.
// You can add *http.ResponseWriter or http.Request in params if you want.
func YourHttpHandler(in *CreateCustomerInput) (CreateCustomerOutput, error) {
	// do some stuff here
	fmt.Printf("%+v", in)

	return CreateCustomerOutput{Name: in.Name}, nil
}

Install

go get github.com/alexisvisco/[email protected]

Compatibility with framework

Benefits

  • More readable code
  • Focus on what it matters: business code
  • No more code duplication with unmarshalling, verifying, validating, marshalling ...
  • You could have one interface for the client and server implementation

📖 Read more...

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