Skip to content
Hoplite
Theme

Begin typing to search this site.

Your first application

  1. Create app.hal and require hoplite.core.

    (ns example.app
    (:require [hoplite.core :as h]))
  2. Define a handler that accepts a request value and returns a response map.

    (defn hello
    [request]
    {:status 200
    :headers {"content-type" "text/plain; charset=utf-8"}
    :body "Hello from Hoplite\n"})
  3. Declare the application and its resource operation.

    (def app
    (h/app
    {:name "example"
    :resources
    [["/hello"
    {:get {:name :hello
    :summary "Return a greeting"
    :handler #'hello}}]]}))
  4. Add the project profile, then check and serve it.

    Terminal window
    hoplite serve check .
    hoplite serve foreground .
    curl -i http://localhost:8080/hello

#'hello stores the handler Var in declarative application data. Calling hello would execute it while the application is being defined. Hoplite resolves the Var and compiles the handler call during worker startup.

A resource is a vector whose first item is an absolute path and whose optional map contains HTTP method operations. Child resource vectors may follow the operation map. Supported operation keys are :get, :post, :put, :patch, :delete, :head, and :options.

Each operation requires :handler. :name and :summary are optional metadata used by generated interface descriptions.