Skip to content

ctx.Request.Body is nil when post json  #22

@tablecell

Description

@tablecell
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions