Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions axum/code-snippet-sharing-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "code-snippet-sharing-app"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
shuttle-axum = "0.57.0"
shuttle-runtime = "0.57.0"
shuttle-shared-db = { version = "0.57.0", features = ["postgres", "sqlx"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
uuid = { version = "1.0", features = ["v4", "serde"] }
chrono = { version = "0.4", features = ["serde"] }
nanoid = "0.4"
sqlx = { version = "0.8", features = [
"runtime-tokio-rustls",
"postgres",
"chrono",
"uuid",
] }
58 changes: 58 additions & 0 deletions axum/code-snippet-sharing-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Code Snippet Share API

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.

---

## Features

- Create, list, view, and delete code snippets.
- Public and private snippet support.
- Tracks view count for each snippet.
- Filter snippets by programming language.
- Lightweight in-memory storage (ideal for tutorials and demos).

---

## Tech Stack

- **Rust** - Fast, safe, and expressive.
- **Axum** - Web framework for building async HTTP APIs.
- **Shuttle** - Rust serverless hosting platform.

---

## Getting Started

### Prerequisites

- Rust (stable)
- Cargo
- Shuttle CLI: [Install Shuttle](https://docs.shuttle.dev/getting-started/installation)

### Run Locally

```bash
shuttle run
```

The API will start on `http://127.0.0.1:8000`

### Deploy to Shuttle

```bash
shuttle deploy
```

Your service will be live with a public URL provided by Shuttle.

### Project Structure

```bash
.
├── Cargo.lock
├── Cargo.toml
├── README.md
└── src
└── main.rs
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS snippets (
id VARCHAR PRIMARY KEY NOT NULL,
content TEXT NOT NULL,
language VARCHAR NOT NULL,
title VARCHAR,
description TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMPTZ,
view_count INTEGER NOT NULL DEFAULT 0,
is_public BOOLEAN NOT NULL DEFAULT true
);

CREATE INDEX IF NOT EXISTS idx_snippets_created_at ON snippets(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_snippets_language ON snippets(language);
CREATE INDEX IF NOT EXISTS idx_snippets_is_public ON snippets(is_public);
CREATE INDEX IF NOT EXISTS idx_snippets_expires_at ON snippets(expires_at);
Loading