📮puttr

A Secure Data Posting Service

puttr is a lightweight web service that allows you to securely send and store data via HTTP PUT requests. Each request is authenticated with a time-limited token and stored with a unique timestamp and organizational structure.

Building

This is a Rust project that uses Cargo. To build the application:

Debug Build

cargo build

Release Build (Optimized)

cargo build --release

Output locations:

Running

Start the web service with one of the following commands:

Using Cargo

cargo run

Using the Compiled Binary

./target/release/puttr
📍 Server Address: The service will start on http://localhost:3000

API Usage

The API consists of two main endpoints: one for requesting authentication tokens and one for posting data.

1

Request an Authentication Token

Before you can send data to the /data endpoint, you need to obtain an authentication token. Tokens are valid for 5 minutes from the time of generation.

Using curl

curl http://localhost:3000/token

Using httpie

http GET http://localhost:3000/token

Response: A base64-encoded token string

WW91IGZvdW5kIGEgdG9rZW4h
2

Send Data with Authorization Token

Once you have a valid token, use it to send data to the /data endpoint via a PUT request. Include the token in the Authorization: Token <value> header. The Content-Type header determines the file extension used to save your data.

Using curl with JSON

curl -X PUT \
  -H "Content-Type: application/json" \
  -H "Authorization: Token WW91IGZvdW5kIGEgdG9rZW4h" \
  -d "content={\"key\": \"value\"}" \
  http://localhost:3000/data

Using curl with Plain Text

curl -X PUT \
  -H "Content-Type: text/plain" \
  -H "Authorization: Token WW91IGZvdW5kIGEgdG9rZW4h" \
  -d "content=hello world" \
  http://localhost:3000/data

Response: 200 OK with body "success"

💾 File Extensions: The file extension is automatically determined by the Content-Type header of your request. For example, use Content-Type: application/json to save as .json or Content-Type: image/png to save as .png. Data is stored in: uploads/YYYY-MM/data-<timestamp>-<token>.<ext>

Complete Example

Here's a complete example that demonstrates the entire workflow in a single shell script:

#!/bin/bash

# Step 1: Get a token
TOKEN=$(curl -s http://localhost:3000/token)
echo "Token: $TOKEN"

# Step 2: Send data with the token
curl -X PUT \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Authorization: Token $TOKEN" \
  -d "content=My important data" \
  http://localhost:3000/data

echo "Data submitted successfully!"

Save this as example.sh, make it executable with chmod +x example.sh, and run it with ./example.sh

Error Handling

The API provides clear HTTP status codes to indicate various error conditions:

401 Unauthorized
Returned when the Authorization header is missing or the token is invalid/expired. Request a new token and retry.
404 Not Found
Returned when the content field is empty or missing in your PUT request. Ensure you include the content parameter with non-empty data.
⏰ Token Expiration: Tokens are valid for 5 minutes. If you receive a 401 error on a previously working token, it has likely expired. Request a new token and try again.

Supported Content Types

The following Content-Type headers are supported for automatic file extension mapping:

Application Types

Text Types

Image Types

Audio Types

Video Types

📝 Default Extension: If you use an unsupported Content-Type, the default .txt extension will be used.

Key Features

Requirements

To build and run puttr, you need:

Installation: If you don't have Rust installed, visit rustup.rs for installation instructions.