Code Monkey home page Code Monkey logo

sketch-coding-challenge's Introduction

ASCII canvas

Server

For simplicity, there is an assumption that (in dev and test mode) you're running the server on a machine with PostgreSQL server installed and listening on the default port (5432). It should allow "trust" authentication with your current system user, which is the default behavior. Should this assumption not apply, you need to specify your database connection properties in the server/config/dev.exs file.

To start the server:

  • Go to the server folder
  • Install dependencies with mix deps.get
  • Create and migrate the database with mix ecto.setup
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Now you can send requests to localhost:4000 from the client.

To run the tests:

  • Go to the server folder
  • Install dependencies with mix deps.get
  • Create and migrate the database with mix ecto.setup
  • Run mix test

API

To test-drive the app, I recommend using the interactive version of the client, which you can find in the interactive-client branch (see below). It's probably more convenient than making direct API calls.

The API endpoints are described below. The data is exchanged in the JSON format, so don't forget to always provide the appropriate Accept and Content-Type HTTP headers.

Create a new canvas

Request: POST /canvases

Example response: {"id": "e15ea634-094f-46a4-8cff-cddbbcd03505"}

Draw a rectangle

Request: POST /canvases/:id/rectangles

Example request data:

{
  "offset_top": 2,
  "offset_left": 3,
  "height": 5,
  "width": 3,
  "fill_character": "X",
  "outline_character": "@"
}

Response: empty, only status 200

Fetch a canvas

Request: GET /canvases/:id

Example response:

{
  "id": "e15ea634-094f-46a4-8cff-cddbbcd03505",
  "rectangles": [
    {
      "offset_top": 2,
      "offset_left": 3,
      "height": 5,
      "width": 3,
      "fill_character": "X",
      "outline_character": "@"
    },
    {
      "offset_top": 3,
      "offset_left": 10,
      "height": 14,
      "width": 6,
      "fill_character": "O",
      "outline_character": "X"
    }
  ]
}

Client

By default, the client expects the server to be available at http://localhost:4000. Should you need the server to be at a different location, please, specify it in the environment variable CANVAS_SERVER_URL.

To use the client:

  • Go to the client folder
  • Install dependencies with mix deps.get
  • Build the binary file with ``./build.sh`
  • Render a canvas with ./canvas_client render 9304172c-baa5-4333-ba9e-3d6f0d93348b

To run the tests:

  • Go to the client folder
  • Install dependencies with mix deps.get
  • Run mix test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.