Backend of the Snippy service - lightning-fast solution for managing code snippets.
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
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"
}
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"
POST /api/lists
Body:
Key | Type | Description |
---|---|---|
name |
string |
Required. Collection name |
Response
{
"data": {
"id": number,
"name": string
}
}
GET /api/lists
Query parameters:
Parameter | Type | Description |
---|---|---|
page |
number |
Page |
limit |
number |
Pagination limit |
Response
{
"data": [
{
"id": number,
"name": string
}
]
}
GET /api/lists/:id
Query parameters:
Parameter | Type | Description |
---|---|---|
id |
number |
Required. Collection ID |
Response
{
"data": {
"id": number,
"name": string
}
}
PUT /api/lists/:id
Body:
Key | Type | Description |
---|---|---|
name |
string |
Required. Collection name |
Response
{
"data": {
"id": number,
"name": string
}
}
DELETE /api/lists/:id
Body:
Key | Type | Description |
---|---|---|
id |
number |
Required. Collection ID |
Response
{
"data": {
"id": number
}
}
POST /api/languages
Body:
Key | Type | Description |
---|---|---|
name |
string |
Required. Language name |
Response
{
"data": {
"id": number
}
}
GET /api/languages
Response
{
"data": [
{
"id": number,
"name": string
}
]
}
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 /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 /api/snippets/:id
Response
{
"data": {
"id": number,
"list_id": number,
"name": string,
"language_id": number,
"description": number,
"content": string
}
}
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 /api/snippets/:id
Response
{
"status": "ok"
}
POST /api/snippets/favourites
Body:
Key | Type | Description |
---|---|---|
id |
number |
Required. Snippet ID |
Response
{
"status": "ok"
}
DELETE /api/snippets/favourites
Body:
Key | Type | Description |
---|---|---|
id |
number |
Required. Snippet ID |
Response
{
"status": "ok"
}
GET /api/snippets/favourites
Response
{
"data": [number]
}
POST /api/tags
Body:
Key | Type | Description |
---|---|---|
name |
string |
Required. Tag ID |
Response
{
"data": {
"id": number
}
}
PUT /api/tags/:id
Body:
Key | Type | Description |
---|---|---|
id |
number |
Required. Tag ID |
Response
{
"status": "ok"
}
DELETE /api/tags/:id
Response
{
"status": "ok"
}
GET /api/tags/:id
Response
{
"data": {
"id": number,
"name": string
}
}
GET /api/tags
Response
{
"data": [
{
"id": number,
"name": string
}
]
}
GET /api/snippets/:id/tags
Response
{
"data": [number]
}
POST /api/snippets/:id/tags
Body:
Key | Type | Description |
---|---|---|
tag_id |
number |
Required. Tag ID |
Response
{
"status": "ok"
}
DELETE /api/snippets/:id/tags
Body:
Key | Type | Description |
---|---|---|
tag_id |
number |
Required. Tag ID |
Response
{
"status": "ok"
}