Overview

You are tasked with creating an API for a poll system. The API should allow users to create and interact with polls, while also ensuring that administrative controls are in place to manage and view all polls. The API will implement basic authentication, allowing actions to be restricted based on user roles. You will be using the Clojure programming language and the Reitit library for routing.

Authentication

The API will use hardcoded authentication with API keys for now. Just assume the Authorisation: header will have one of the following API keys:

(def auth-keys
  {:admin {:api-key "123adminkey"}
   :user1 {:api-key "123user1"}
   :user2 {:api-key "123user2"}})

What’s a poll

A poll will have at least the following data which you will receive via POST. You can assume this comes in EDN format.

The structure is purposefully vague, we’d like your input into how a good poll design may look. Please consider this data structure carefully and extend it as you see fit given the task at hand.

Notification of poll change

We would like the system to be able to notify listeners of changes to a poll - please account for something in your submission to make this possible. Long polling or websockets are a couple of ways you might achieve this.

Assumptions

  1. In-Memory Data: The poll data will be stored in memory. There is no need for a database or persistent storage. However, if you’d like to go a step further and include an example rdbms schema, please do.
  2. User Authentication: Authentication is performed based on the Authorization header using API keys.
  3. Errors: Handle errors gracefully, returning proper HTTP status codes.