/png2ascii-api

A toy API to convert PNG binary data to an ASCII-fied image

Primary LanguageGoMIT LicenseMIT

png2ascii API

Overview

An HTTP service that accepts an image, and creates an ASCII version of that image that can be retrieved later.

Features:

  • GET /images returns a list of all available images
  • GET /images/<image_id> returns the ASCII representation of an image
  • POST /images accepts a new PNG image to be converted to ASCII
  • POST /images returns a newly minted ID for the uploaded image
  • ASCII-fied Data Persistence as files on Disk

Implementation

The png2ascii-api uses the Fiber web framework to capture PNG image files and ASCII-fy them (with image2ascii), responding with a unique identifier that can be used to retrieve the ASCII-fied image. The ASCII images are persisted, so if the service is stopped and restarted, the data should still be available.

Usage

  • make build to build a Docker container
  • make service to start the service on port 8080 -- Note: host & port is hard-coded
  • make test to run API feature tests -- includes testing ASCII-fying and directory existence

Examples

POST an image:

$ curl -X POST --data-binary @IMAGE.png localhost:8080/images

GET avliable ASCII image or list avaliable ASCII images:

$ curl http://localhost:8080/images/<image_id>

$ curl http://localhost:8080/images/

Improvements

  • Testing could be improved (i.e start the server and then perform tests)
  • Logging needs work
  • Concurrent requests could be implemented
  • Storing temporary image files is not super efficient and could be improved
  • Cache management could be implemented for obtaining all available images / requested image

Resources