Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctx

Request-response utility for every HTTP context

Usage

package main

import (
	"net/http"

	"github.com/ngamux/ctx"
	"github.com/ngamux/ngamux"
)

func main() {
	mux := ngamux.New()

	mux.Post("/", func(rw http.ResponseWriter, r *http.Request) {
		c := ctx.New(rw, r)

		var data interface{}
		if err := c.Req().JSON(&data); err != nil {
			c.Res().Status(http.StatusBadRequest).JSON(ngamux.Map{
				"error": err.Error(),
			})
			return
		}

		c.Res().Status(http.StatusOK).JSON(data)
	})

	http.ListenAndServe(":8080", mux)
}

About

Request-response utility for every HTTP context

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages