An example of REST API made with Go. A simple Task API.
- Go 1.11+
sqlite3
commandline tool
- Copy the
example.env
to.env
and change its content as you want. - Run
make db
to create a sqlite3 database with an initial data. (Optional, if you already have a database file.) - Build and run the project with
make run
. - Enjoy the API.
Available endpoints and usage example.
Returns all stored tasks.
GET /tasks/
Code | Description |
---|---|
200 | Ok |
500 | Internal Server Error |
[
{
"id": 1,
"title": "Task 01",
"priority": 0,
"done": true
},
{
"id": 2,
"title": "Task 02",
"priority": 1,
"done": false
},
{
"id": 3,
"title": "Task 03",
"priority": 99,
"done": false
}
]
Stores a new task.
POST /tasks/
{
"title": "A Task",
"priority": 5,
"done": false
}
Code | Description |
---|---|
201 | Created |
400 | Bad Request |
500 | Internal Server Error |
{
"id": 2,
"title": "A Task",
"priority": 5,
"done": false
}
Returns a tasks by its id.
GET /tasks/:id/
Code | Description |
---|---|
200 | Ok |
400 | Bad Request |
404 | Not Found |
500 | Internal Server Error |
{
"id": 1,
"title": "Task 01",
"priority": 0,
"done": true
}
Updates a stored task with the provided data by its id.
PUT /tasks/:id/
{
"title": "Updated Task",
"priority": 7,
"done": false
}
Code | Description |
---|---|
200 | Ok |
400 | Bad Request |
404 | Not Found |
500 | Internal Server Error |
{
"id": 3,
"title": "Updated Task",
"priority": 7,
"done": false
}
Removes a stored task by its id.
DELETE /tasks/:id/
Code | Description |
---|---|
200 | Ok |
400 | Bad Request |
404 | Not Found |
500 | Internal Server Error |
{
"id": 4,
"title": "Deleted Task",
"priority": 11,
"done": true
}