A very basic "clone" of Reddit's r/place written in Rust using warp

Overview

r(usty)/place

A very basic "clone" of r/place written in Rust using warp.

Instead of rendering the image on the client side, the image is encoded as PNG and sent to the user. This doesn't scale well as that image is constructed every time someone sends a GET requests to /image. Ideally, you would render the image client-side and e.g. using WebSockets, send them notifications when a pixel was edited.

Features

There aren't that many:

  • When the server shuts down, the image data is stored in a file image and loaded back up when the server starts again.

API

GET / basic welcoming message

Responses

HTTP code content-type response
200 application/json {"code":200,"message":"Welcome to r/place but in Rust!"}

Example

$ curl -X GET http://localhost:3030/
GET /image sends the current canvas

Responses

HTTP code content-type response
200 image/png

Example

$ curl -X GET http://localhost:3030/image > image.png
PUT /set-pixel/:x/:y set the color of a pixel

Parameters

name type data type description
x required usize The x position of the pixel
y required usize The y position of the pixel

Body

  • max. Content-Length is 32 bytes
  • hex_color has to be string of length 6
{
    "color": hex_color
}

Example:

{"color":"FFFFFF"}

Header

name type data type description
X-Token required String The "auth" token (has to be set to abc)

Responses

HTTP code content-type response description
200 application/json {"code":200,"message":"Successfully edited pixel"}
400 application/json {"code":400,"message":"MISSING_HEADER: X-Token"}
401 application/json {"code":401,"message":"BAD_AUTH"} X-Token wasn't abc
411 application/json {"code":411,"message":"MISSING_CONTENT_LENGTH"} Missing body
413 application/json {"code":413,"message":"PAYLOAD_TOO_LARGE"} Body too big (max. 32 bytes)
422 application/json {"code":422,"message":"MALFORMED_BODY"} Body couldn't be parsed to JSON
422 application/json {"code":422,"message":"OUT_OF_BOUNDS"} Pixel out of bounds
422 application/json {"code":422,"message":"INVALID_COLOR"} Invalid hex color

Example

$ curl -X PUT -H "X-Token: abc" -H "Content-Type: application/json" -d "{\"color\":\"ffffff\"}" http://localhost:3030/set-pixel/10/10

Future ideas

  • "proper" authentication i.e. creating accounts with unique auth tokens
  • rate limits to prevent spamming
You might also like...
An API project using Rust, Actix Web and JWT. *WIP*

Actix-web REST API with JWT (WIP) A simple CRUD backend app using Actix-web, Diesel and JWT Require Rust Stable Postgres Or using Docker How to run Ma

The goal of this repository is to have a real world template of a Rust backend using Axum, Diesel, etc.

Axum Diesel Real-World Example A modular Rust backend template based on the Domain-Driven Design (DDD) architecture, utilizing the Axum and Diesel fra

A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.
A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.

Mini Google Course project for the Architecture of Computer Systems course. Overview: Architecture: We are working on multiple components of the web c

Share files between devices using your Wi-Fi network.
Share files between devices using your Wi-Fi network.

swift_file Rust implementation of transferring files between devices over Wi-Fi network using a QR code. Tool is inspired by claudiodangelis/qrcp. How

Sample Artemis bot to fill UniswapX orders using on-chain liquidity

UniswapX Atomic Filler This is a sample Artemis bot that fills UniswapX orders atomically using Uniswap v2 and v3 liquidity. Feel free to fork and mod

Code template for a production Web Application using Axum: The AwesomeApp Blueprint for Professional Web Development.

AwesomeApp rust-web-app More info at: https://awesomeapp.dev/rust-web-app/ rust-web-app YouTube episodes: Episode 01 - Rust Web App - Course to Produc

An occult chat app using Cabal 🧙✨🔮
An occult chat app using Cabal 🧙✨🔮

coven 🧙✨🔮 An occult chat app using Cabal Uses the cable.rs implementation of the new Cable protocol. For now is a desktop app, but with the magic of

A html document syntax and operation library written in Rust, use APIs similar to jQuery.

Visdom A server-side html document syntax and operation library written in Rust, it uses apis similar to jQuery, left off the parts thoes only worked

A Blog & RSS system written in Rust based on Luke Smith's LB.
A Blog & RSS system written in Rust based on Luke Smith's LB.

OB - Oliver's Blog Script A Blog and RSS system written in Rust. Features Converts blog entries written in Markdown into HTML. ✍🏻 Keeps a rolling blo

Owner
canta slaus
i like vimbs \ discord: canta#5556
canta slaus
A simple clone of Waifu-pics written in Rust

really A simple clone of Waifu-pics written in Rust. Why? I've no idea. API Doc GET /api/v1/meta GET /api/v1/by/:type/:category GET /api/v1/random GET

Nik 2 Dec 18, 2022
X/Twitter clone in Axum 0.7.1

X / Twitter Clone If we removed everything other than the basics of x/twitter, we have a micro-blogging platform with the following features which we'

Brooks Builds 6 Dec 9, 2023
Experiments with Rust CRDTs using Tokio web application framework Axum.

crdt-genome Synopsis Experiments with Rust CRDTs using Tokio web application framework Axum. Background Exploring some ideas of Martin Kleppmann, part

dougfort 3 Mar 18, 2022
Scratch-Containerised Rust GraphQL-API using Dataloaders

Dockerize Graphql Rust More current version at https://github.com/jayy-lmao/rust-cult-graphql-server This project is currently for demonstrating the u

James H. 89 Dec 3, 2022
Web Application with using Rust(Actix, Diesel and etc)

Santa Service App Used technology stack Web Server with using Rust (Actix, Actix-web, Diesel) Data base (Postgres) Console Application (Tokio) Tasks o

null 3 Jan 8, 2023
A simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit frontend.

Rust-auth-example This repository aims to represent a simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit

Kival Mahadew 4 Feb 19, 2023
Proof of concept writing a monolith BBS using Rust, GraphQL, WASM, and SQL. WILL BE ARCHIVED ONCE PROVEN

GraphQL Forum Important DO NOT even think about using this in production, lest your sanity be destroyed and credentials lost! Loosely following the aw

Rongcui Dong 25 Apr 25, 2023
Rust GraphQL server using simple type-only schema

SimpleGQL This library allows a simplified GraphQL schema to be given and will run a server with a backend store (currently only SQLite) and a set of

Daniel Cocks 5 May 10, 2023
Rust HTTP API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture

Rust Template HTTP API Rust API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture The following template provides a basic structu

Paulo Bressan 7 Jun 9, 2023
JWT Authentication in Rust using Axum Framework

Are you interested in building a secure authentication system for your Rust web application? Look no further than the Axum framework and JSON Web Tokens (JWTs)! Axum is a fast and scalable Rust web framework that provides a reliable and efficient platform for developing microservices and APIs.

CODEVO 16 Jun 11, 2023