Client-server system representing an ASCII art drawing canvas. It implements:
- JSON based RESTful endpoint
- Two canvas operations - rectangle drawing and flood-fill
- Erlang
DETSbased canvas persistence mechanism (no DB needed!) Phenix LiveViewbased client (read only)
- Clone repo with
git clone https://github.com/Kociamber/sketch.git(or unzip the package if you got it from Joanna ;]) - Enter the folder (
cd sketch) and perform required setup withmix setup - Start the endpoint with
mix runoriex -S mix phx.server(with interactive console)
To access LiveView based client visit localhost:4000 from your browser.
After the setup your local storage is empty - you can quickly create (an assignment test fixture based) canvas you can run the seedfile with mix seed.
To "clear" your storage run mix clear_storage or simply delete sketch_storage file from the project's root directory.
Browser's routes:
/ - shows all locally stored canvases
/:id - shows a specific canvas
JSON endpoint requests routes:
post/canvas: creates, persists and returns empty canvas, no body params requiredget/canvas: returns a list of currently stored canvasesget/canvas/:id: returns canvas by id, no body params requiredput/canvas/:id: performs flood or rectangle draw operation, returns "updated" canvas (requred body params below)delete/canvas/:id- removes canvas and returns deleted structure, no body params required
Body params required for put (canvas drawing operation) - drawing rectangle:
{"operation":"rectangle","x":7, "y":10,"width":40,"height":15,"fill_char":"#", "outline_char":"+"}- all params are mandatory (besides
fill_charandoutline_char- only one of them must be present) - all numeric values must be integers greater than or equal 0
fill_charandoutline_charcan be only strings of length 1
Flood operation required params:
{"operation":"flood","x":3, "y":3,"fill_char":"7"}- all params are mandatory
- all numeric values must be integers greater than or equal 0
fill_charcan be only a strings of length 1
The server is performing request parameters validation and in case of missing or incorrect values json error message is being returned.
Get a list of all stored canvases:
curl -H "Content-Type: application/json" -X GET http://localhost:4000/api/canvas/Create new canvas:
curl -H "Content-Type: application/json" -X POST http://localhost:4000/api/canvas/Get canvas by id:
curl -H "Content-Type: application/json" -X GET http://localhost:4000/api/canvas/:canvas_idPerform rectangle drawing operation:
curl -H "Content-Type: application/json" -X PUT -d '{"operation":"rectangle","x":1, "y":2,"width":5,"height":5,"fill_char":"#"}' http://localhost:4000/api/canvas/:canvas_idPerform fill-flood operation:
curl -H "Content-Type: application/json" -X PUT -d '{"operation":"flood","x":3, "y":2,"fill_char":"^"}' http://localhost:4000/api/canvas/:canvas_idRemove canvas from the storage:
curl -H "Content-Type: application/json" -X DELETE http://localhost:4000/api/canvas/:canvas_idAll operations are returning a canvas of following structure:
{"canvas":{"content":{"0":{"0":"-","1":"-","2":"-","3":"-","4"},...,"id":"ee25fbec-2767-11eb-8a6f-784f436f155b"}}}