HTTP Flake ID generation service.
Blizzard provides a Ring middleware which adds two routes, /flake and /flake/:n which generate a single flake and N flakes, respectively. Responses are of content type application/transit+json and as such a transit client should be used to read them.
While Blizzard may to used as a standalone service, because it is implemented as as a middleware it can be attached to any application where the routes do not conflict. For example:
=> (def handler (-> (constantly {:status 404 :body "Not Found"}) wrap-flake))
Of course, other middleware may be added as desired. Note that above handler should be passed to an adapter such as ring-jetty.
For standalone use, the following environment variables provide runtime configuration:
BLIZZARD_HOST - Defaults to localhost. BLIZZARD_PORT - Defaults to 3000. BLIZZARD_MAX_IDS - The maximum allowed IDs per batch request. Default 1000. BLIZZARD_JETTY_OPTS - Defaults to {:join? true}.
HTTP Flake ID generation service.
Blizzard provides a Ring middleware which adds two routes, /flake and
/flake/:n which generate a single flake and N flakes, respectively. Responses
are of content type application/transit+json and as such a transit client
should be used to read them.
While Blizzard may to used as a standalone service, because it is implemented
as as a middleware it can be attached to any application where the routes do
not conflict. For example:
=> (def handler (-> (constantly {:status 404 :body "Not Found"})
wrap-flake))
Of course, other middleware may be added as desired. Note that above handler
should be passed to an adapter such as ring-jetty.
For standalone use, the following environment variables provide runtime
configuration:
BLIZZARD_HOST - Defaults to localhost.
BLIZZARD_PORT - Defaults to 3000.
BLIZZARD_MAX_IDS - The maximum allowed IDs per batch request. Default
1000.
BLIZZARD_JETTY_OPTS - Defaults to {:join? true}.(accept->fmt accept)Returns a transit format (either :json or :msgpack, defaulting to :json) based on the value of the Accept header.
Returns a transit format (either :json or :msgpack, defaulting to :json) based on the value of the Accept header.
(get-env k & [default])Gets an environment variable k. An optional default is used when values are missing.
Gets an environment variable k. An optional default is used when values are missing.
(ids-response method max-ids fmt & [{:keys [n] :or {n "1"}}])Returns a response with an appropriate number of ids.
Returns a response with an appropriate number of ids.
(n-or-1 n)Returns n if n is greater than 0 otherwise 1.
Returns n if n is greater than 0 otherwise 1.
(n-or-max-ids n max-ids)Returns n if n is equal to or less than max-ids.
Returns n if n is equal to or less than max-ids.
(string->integer s)Converts s to an integer.
Converts s to an integer.
(take-ids n)Repeatedly calls flake/generate n times, returns the result.
Repeatedly calls flake/generate n times, returns the result.
(transit-write data fmt)Writes data with the given fmt (either :json or :msgpack) into a ByteArrayOutputStream as transit data. Returns the output stream.
Writes data with the given fmt (either :json or :msgpack) into a ByteArrayOutputStream as transit data. Returns the output stream.
(wrap-flake handler & [{:keys [max-ids]}])Middleware that adds two routes to a Ring application:
/flake - Returns a single Flake ID. /flake/:n - Returns N Flake IDs.
Takes an optional map containing a key max-id, the maximum allowed number of keys. Defaults to 1000.
Middleware that adds two routes to a Ring application: /flake - Returns a single Flake ID. /flake/:n - Returns N Flake IDs. Takes an optional map containing a key max-id, the maximum allowed number of keys. Defaults to 1000.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |