go-rest-api

command module
v0.0.0-...-138ac3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2018 License: MIT Imports: 9 Imported by: 0

README

go-rest-api

An example of REST API made with Go. A simple Task API.

Requirements

  • Go 1.11+
  • sqlite3 commandline tool

Usage

  1. Copy the example.env to .env and change its content as you want.
  2. Run make db to create a sqlite3 database with an initial data. (Optional, if you already have a database file.)
  3. Build and run the project with make run.
  4. Enjoy the API.

Endpoints

Available endpoints and usage example.

List Tasks

Returns all stored tasks.

URL

GET /tasks/

Response Status
Code Description
200 Ok
500 Internal Server Error
Response Data
[
    {
        "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
    }
]
Create a Task

Stores a new task.

URL

POST /tasks/

Payload
{
    "title": "A Task",
    "priority": 5,
    "done": false
}
Response Status
Code Description
201 Created
400 Bad Request
500 Internal Server Error
Response Data
{
    "id": 2,
    "title": "A Task",
    "priority": 5,
    "done": false
}
Get a Task

Returns a tasks by its id.

URL

GET /tasks/:id/

Response Status
Code Description
200 Ok
400 Bad Request
404 Not Found
500 Internal Server Error
Response Data
{
    "id": 1,
    "title": "Task 01",
    "priority": 0,
    "done": true
}
Update a Task

Updates a stored task with the provided data by its id.

URL

PUT /tasks/:id/

Payload
{
    "title": "Updated Task",
    "priority": 7,
    "done": false
}
Response Status
Code Description
200 Ok
400 Bad Request
404 Not Found
500 Internal Server Error
Response Data
{
    "id": 3,
    "title": "Updated Task",
    "priority": 7,
    "done": false
}
Delete a Task

Removes a stored task by its id.

URL

DELETE /tasks/:id/

Response Status
Code Description
200 Ok
400 Bad Request
404 Not Found
500 Internal Server Error
Response Data
{
    "id": 4,
    "title": "Deleted Task",
    "priority": 11,
    "done": true
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL