Skip to content

Backend of Snippy web service [Go, Gin, PostgreSQL]

License

Notifications You must be signed in to change notification settings

mbredikhin/snippy

Repository files navigation

Snippy

Backend of the Snippy service - lightning-fast solution for managing code snippets.

Installation and run

git clone [email protected]:mbredikhin/snippy.git && cd snippy
# Build services
make build
# Create and start containers
make run
# Run database migrations
make migrate-up
# Seed database
make db-seed
# API host name: https://localhost:8001
# curl -X POST --data '{"username":"username", "password":"password"}' https://localhost:8001/auth/sign-in
# curl -X POST --data '{"name":"My snippets collection"}' --header 'Authorization: Bearer {{token}}' https://localhost:8001/api/lists

API Reference

Run In Postman

Register new user

  POST /auth/sign-up

Body:

Key Type Description
username string Required. Your username
password string Required. Your password
name string Your full name

Response

{
    "status": "ok"
}

Login with username and password

  POST /auth/sign-in

Body:

Key Type Description
username string Required. Your username
password string Required. Your password

Response

{
    "data": {
        "token": string
    }
}

Send given token in Authorization HTTP header – Authorization: "Bearer %s"

Create a new list of snippets

  POST /api/lists

Body:

Key Type Description
name string Required. Collection name

Response

{
    "data": {
        "id": number,
        "name": string
    }
}

Get all lists

  GET /api/lists

Query parameters:

Parameter Type Description
page number Page
limit number Pagination limit

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}

Get list by id

  GET /api/lists/:id

Query parameters:

Parameter Type Description
id number Required. Collection ID

Response

{
    "data": {
        "id": number,
        "name": string
    }
}

Update list

  PUT /api/lists/:id

Body:

Key Type Description
name string Required. Collection name

Response

{
    "data": {
        "id": number,
        "name": string
    }
}

Delete list

  DELETE /api/lists/:id

Body:

Key Type Description
id number Required. Collection ID

Response

{
    "data": {
        "id": number
    }
}

Add language

  POST /api/languages

Body:

Key Type Description
name string Required. Language name

Response

{
    "data": {
        "id": number
    }
}

Get list of languages

  GET /api/languages

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}

Create new snippet

  POST /api/lists/:id/snippets

Body:

Key Type Description
name string Required. Snippet name
language_id number Required. Language ID
description string Required. Text description
content string Required. Snippet content

Response

{
    "data": {
        "id": number
    }
}

Get all snippets of the list

  GET /api/lists/:id/snippets

Query parameters:

Parameter Type Description
tag_ids number[] Filters snippets with any of entered tags assigned
page number Page
limit number Pagination limit

Response

{
    "data": [
        {
            "id": number,
            "list_id": number,
            "name": string,
            "language_id": number,
            "description": string,
            "content": string
        }
    ]
}

Get snippet

  GET /api/snippets/:id

Response

{
    "data": {
        "id": number,
        "list_id": number,
        "name": string,
        "language_id": number,
        "description": number,
        "content": string
    }
}

Update snippet

  PUT /api/snippets/:id

Body:

Key Type Description
name string Required. Snippet name
language_id number Required. Language ID
list_id number Required. Collection ID
description string Required. Text description
content string Required. Snippet content

Response

{
    "status": "ok"
}

Delete snippet

  DELETE /api/snippets/:id

Response

{
    "status": "ok"
}

Add snippet to favourites

  POST /api/snippets/favourites

Body:

Key Type Description
id number Required. Snippet ID

Response

{
    "status": "ok"
}

Remove snippet from favourites

  DELETE /api/snippets/favourites

Body:

Key Type Description
id number Required. Snippet ID

Response

{
    "status": "ok"
}

Get ids of favourite snippets

  GET /api/snippets/favourites

Response

{
    "data": [number]
}

Add tag

  POST /api/tags

Body:

Key Type Description
name string Required. Tag ID

Response

{
    "data": {
        "id": number
    }
}

Update tag

  PUT /api/tags/:id

Body:

Key Type Description
id number Required. Tag ID

Response

{
    "status": "ok"
}

Delete tag

  DELETE /api/tags/:id

Response

{
    "status": "ok"
}

Get tag

  GET /api/tags/:id

Response

{
    "data": {
        "id": number,
        "name": string
    }
}

Get list of tags

  GET /api/tags

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}

Get list of tags assigned to the snippet

  GET /api/snippets/:id/tags

Response

{
    "data": [number]
}

Assign tag to the snippet

  POST /api/snippets/:id/tags

Body:

Key Type Description
tag_id number Required. Tag ID

Response

{
    "status": "ok"
}

Unassign tag from the snippet

  DELETE /api/snippets/:id/tags

Body:

Key Type Description
tag_id number Required. Tag ID

Response

{
    "status": "ok"
}

About

Backend of Snippy web service [Go, Gin, PostgreSQL]

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages