Skip to content

Commit 72ae286

Browse files
authored
New Template: Snippet Sharing App (#229)
1 parent 5636612 commit 72ae286

12 files changed

Lines changed: 661 additions & 0 deletions

axum/code-snippet-sharing-app/.sqlx/query-40f717379ce15156cabe7bd200bacf5ddf9c87a872574afeb20289627a897e7a.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-49969fd63526646bb069216573be8ad247d633fa8a073bdc0c6648089b5b0d4e.json

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-4d8ecc221df32f11c2b6143999f130ff18e38de22b685489bb6f8eb0abacf281.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-89b5d73a044dbac1f3463535b7d6eb431b51deb808b8b92c547acca53bb6fe55.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-9bed2880002e53cc7187b8b68256138694ecbe8df8f3618210232ad45d3d7a0c.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-a409ebc9ab67f4cbd9daa9e0209afd5c04ba143a352ab0dcea6cfe980721cd5f.json

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axum/code-snippet-sharing-app/.sqlx/query-b8207efb0a5e77f676e17f0c68e30e58455d4f915bc0a0c481ce77a1aff2828c.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "code-snippet-sharing-app"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
axum = "0.8"
8+
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
9+
shuttle-axum = "0.57.0"
10+
shuttle-runtime = "0.57.0"
11+
shuttle-shared-db = { version = "0.57.0", features = ["postgres", "sqlx"] }
12+
serde = { version = "1.0", features = ["derive"] }
13+
serde_json = "1.0"
14+
uuid = { version = "1.0", features = ["v4", "serde"] }
15+
chrono = { version = "0.4", features = ["serde"] }
16+
nanoid = "0.4"
17+
sqlx = { version = "0.8", features = [
18+
"runtime-tokio-rustls",
19+
"postgres",
20+
"chrono",
21+
"uuid",
22+
] }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Code Snippet Share API
2+
3+
A lightweight API for sharing code snippets, built with **Rust**, **Axum**, and **Shuttle**. This hands-on tutorial demonstrates how to build, deploy, and manage a snippet-sharing service in the cloud.
4+
5+
---
6+
7+
## Features
8+
9+
- Create, list, view, and delete code snippets.
10+
- Public and private snippet support.
11+
- Tracks view count for each snippet.
12+
- Filter snippets by programming language.
13+
- Lightweight in-memory storage (ideal for tutorials and demos).
14+
15+
---
16+
17+
## Tech Stack
18+
19+
- **Rust** - Fast, safe, and expressive.
20+
- **Axum** - Web framework for building async HTTP APIs.
21+
- **Shuttle** - Rust serverless hosting platform.
22+
23+
---
24+
25+
## Getting Started
26+
27+
### Prerequisites
28+
29+
- Rust (stable)
30+
- Cargo
31+
- Shuttle CLI: [Install Shuttle](https://docs.shuttle.dev/getting-started/installation)
32+
33+
### Run Locally
34+
35+
```bash
36+
shuttle run
37+
```
38+
39+
The API will start on `http://127.0.0.1:8000`
40+
41+
### Deploy to Shuttle
42+
43+
```bash
44+
shuttle deploy
45+
```
46+
47+
Your service will be live with a public URL provided by Shuttle.
48+
49+
### Project Structure
50+
51+
```bash
52+
.
53+
├── Cargo.lock
54+
├── Cargo.toml
55+
├── README.md
56+
└── src
57+
└── main.rs
58+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE IF NOT EXISTS snippets (
2+
id VARCHAR PRIMARY KEY NOT NULL,
3+
content TEXT NOT NULL,
4+
language VARCHAR NOT NULL,
5+
title VARCHAR,
6+
description TEXT,
7+
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
expires_at TIMESTAMPTZ,
9+
view_count INTEGER NOT NULL DEFAULT 0,
10+
is_public BOOLEAN NOT NULL DEFAULT true
11+
);
12+
13+
CREATE INDEX IF NOT EXISTS idx_snippets_created_at ON snippets(created_at DESC);
14+
CREATE INDEX IF NOT EXISTS idx_snippets_language ON snippets(language);
15+
CREATE INDEX IF NOT EXISTS idx_snippets_is_public ON snippets(is_public);
16+
CREATE INDEX IF NOT EXISTS idx_snippets_expires_at ON snippets(expires_at);

0 commit comments

Comments
 (0)