jas icon indicating copy to clipboard operation
jas copied to clipboard

ctx.Request.Body is nil when post json

Open tablecell opened this issue 2 years ago • 0 comments

package main

import(
"github.com/coocood/jas"
"net/http"
 "fmt"
"bytes"
)
type Add struct {}
 
func (*Add) Get (ctx *jas.Context) { 
	ctx.Data = "hello world"
 
}
func (*Add) Post (ctx *jas.Context) { 
 

    buf:=new(bytes.Buffer)
    buf.ReadFrom(ctx.Request.Body)

    fmt.Println(buf.String())


	ctx.Data = " world hello"
 
}
func main () {
router := jas.NewRouter(new(Add))
	http.Handle("/", router)
 http.ListenAndServe(":8080", nil)
}

curl -X POST http://localhost:8080/add -H "Content-Type: application/json" -d @data.json

tablecell avatar Oct 13 '23 10:10 tablecell