A simple RESTful API for a blog, built with Rocket and Diesel in Rust.
- User creation
- Post creation (with tags)
- List posts (with pagination, search, and user info)
- PostgreSQL database
| Method | Path | Description |
|---|---|---|
| POST | /users | Create a new user |
| POST | /posts | Create a new post |
| GET | /posts | List posts (paginated) |
curl -X POST http://localhost:8000/users \
-H "Content-Type: application/json" \
-d '{"username":"testuser","first_name":"Test","last_name":"User"}'curl -X POST http://localhost:8000/posts \
-H "Content-Type: application/json" \
-d '{"post":{"title":"Hello","body":"World","created_by":1},"tags":["rust","api"]}'curl "http://localhost:8000/posts?page=1&per_page=10&search=hello"-
Install PostgreSQL and create a database.
-
Set your database URL in
Rocket.toml:[default.databases] blog_db = { url = "postgres://username:password@localhost/blog_db" }
-
Run Diesel migrations:
diesel setup diesel migration run
cargo runThe API will be available at http://localhost:8000.