Created

设置HTTP请求的响应码为201,并设置响应体,等价于调用c.StatusCode = 201; c.Body = x;

Example

  1. // curl -XPOST 'http://127.0.0.1:3000/' -v
  2. package main
  3. import (
  4. "github.com/vicanso/elton"
  5. "github.com/vicanso/elton/middleware"
  6. )
  7. func main() {
  8. e := elton.New()
  9. e.Use(middleware.NewDefaultResponder())
  10. e.POST("/", func(c *elton.Context) (err error) {
  11. c.Created(map[string]string{
  12. "account": "tree.xie",
  13. })
  14. return
  15. })
  16. err := e.ListenAndServe(":3000")
  17. if err != nil {
  18. panic(err)
  19. }
  20. }