Example #1
0
func (c *TodoContext) Create(rw web.ResponseWriter, req *web.Request) {
	todo := &Todo{}
	c.UnmarshalBody(rw, req, &todo)
	todo.Id = ""
	todo.CreatedAt = time.Now()

	id, err := c.TodoService.Create(todo)
	if err != nil {
		rw.WriteHeader(http.StatusBadRequest)
		log.Panicln(err)
	}

	rw.Header().Set("Location", "/todos/"+id)
	rw.WriteHeader(http.StatusCreated)
}