Documentation
¶
Overview ¶
This package implements a simple HTTP server providing a REST API to a task handler.
It provides four methods:
GET /task/ Retrieves all the tasks.
POST /task/ Creates a new task given a title.
GET /task/{taskID} Retrieves the task with the given id.
PUT /task/{taskID} Updates the task with the given id.
Every method below gives more information about every API call, its parameters, and its results.
Index ¶
Constants ¶
const PathPrefix = "/task/"
Variables ¶
This section is empty.
Functions ¶
func GetTask ¶
func GetTask(w http.ResponseWriter, r *http.Request) error
GetTask handles GET requsts to /task/{taskID}. There's no parameters and it returns a JSON encoded task.
Examples:
req: GET /task/1
res: 200 {"ID": 1, "Title": "Buy bread", "Done": true}
req: GET /task/42
res: 404 task not found
func ListTasks ¶
func ListTasks(w http.ResponseWriter, r *http.Request) error
ListTask handles GET requests on /task. There's no parameters and it returns an object with a Tasks field containing a list of tasks.
Example:
req: GET /task/
res: 200 {"Tasks": [
{"ID": 1, "Title": "Learn Go", "Done": false},
{"ID": 2, "Title": "Buy bread", "Done": true}
]}
func NewTask ¶
func NewTask(w http.ResponseWriter, r *http.Request) error
NewTask handles POST requests on /task. The request body must contain a JSON object with a Title field. The status code of the response is used to indicate any error.
Examples:
req: POST /task/ {"Title": ""}
res: 400 empty title
req: POST /task/ {"Title": "Buy bread"}
res: 200
func RegisterHandlers ¶
func RegisterHandlers()
func UpdateTask ¶
func UpdateTask(w http.ResponseWriter, r *http.Request) error
UpdateTask handles PUT requests to /task/{taskID}. The request body must contain a JSON encoded task.
Example:
req: PUT /task/1 {"ID": 1, "Title": "Learn Go", "Done": true}
res: 200
req: PUT /task/2 {"ID": 2, "Title": "Learn Go", "Done": true}
res: 400 inconsistent task IDs
Types ¶
This section is empty.