Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Latest commit

 

History

History

03-json

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

3. JSON see notes

  • Create a type Todo with fields for ID, Title, Completed, URL, and Order
  • Rename the Echo handler to ListTodos
  • Create a slice of Todo values with some dummy data.
  • Marshal the slice to JSON and write it to the client.
  • Use w.WriteHeader to explicitly set the response status code.
  • Include the Content-Type header so clients understand the response. w.Header().Set("Content-Type", "application/json; charset=utf-8")
  • See what happens when a nil slice is provided.

File Changes:

Modified main.go