A Secure Data Posting Service
This is a Rust project that uses Cargo. To build the application:
cargo build
cargo build --release
Output locations:
target/debug/puttrtarget/release/puttrStart the web service with one of the following commands:
cargo run
./target/release/puttr
http://localhost:3000
The API consists of two main endpoints: one for requesting authentication tokens and one for posting data.
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.
curl http://localhost:3000/token
http GET http://localhost:3000/token
Response: A base64-encoded token string
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.
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Token WW91IGZvdW5kIGEgdG9rZW4h" \
-d "content={\"key\": \"value\"}" \
http://localhost:3000/data
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"
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>
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
The API provides clear HTTP status codes to indicate various error conditions:
Authorization header is missing or the token is invalid/expired. Request a new token and retry.
content field is empty or missing in your PUT request. Ensure you include the content parameter with non-empty data.
401 error on a previously working token, it has likely expired. Request a new token and try again.
The following Content-Type headers are supported for automatic file extension mapping:
application/json → .jsonapplication/xml → .xmlapplication/pdf → .pdfapplication/zip → .zipapplication/gzip → .gzapplication/x-tar → .tarapplication/x-rar-compressed → .rarapplication/octet-stream → .bintext/plain → .txttext/html → .htmltext/css → .csstext/javascript → .jstext/csv → .csvtext/yaml → .yamltext/markdown → .mdimage/png → .pngimage/jpeg → .jpgimage/gif → .gifimage/webp → .webpimage/svg+xml → .svgimage/bmp → .bmpimage/tiff → .tiffimage/x-icon → .icoaudio/mpeg → .mp3audio/wav → .wavaudio/webm → .webmaudio/flac → .flacaudio/ogg → .oggaudio/aac → .aacvideo/mp4 → .mp4video/webm → .webmvideo/mpeg → .mpegvideo/quicktime → .movvideo/x-msvideo → .avivideo/x-matroska → .mkvvideo/x-flv → .flv.txt extension will be used.
To build and run puttr, you need:
uploads/ directoryInstallation: If you don't have Rust installed, visit rustup.rs for installation instructions.