Sean Walker

Takes hikesand makes sites


coast on clojure

Hey, I'm Sean 👋, I like writing clojure and making websites quickly and easily. I've been making websites for about 20 years now, and I've gone through quite a few different frameworks, libraries and the like to know what suits me and maybe what suits you too!

When I'm not programming, I like to try and promote my websites around the internet, I also like to get outdoors often with my wife and my dog. I also play a mean game of settlers of catan.

What is coast on clojure?

Coast on clojure is a rails-inspired "full stack web framework" for making websites, or if you don't want to be fancy, it's a bunch of clojure code that helps you make websites.

I say websites, not web apps, because I think there's a lot of confusion over what makes something a web app vs a site. Heavy use of javascript frameworks come to mind when talking about web apps, which is something I don't really find to be terribly useful when you make websites as a one man band.

So coast focuses on ease of use above all else. When you're making websites with coast and it isn't easy or obvious on how to proceed, go ahead and send an issue my way, and I'll probably push it to master right away!

Why coast on clojure?

You should choose coast on clojure if you like clojure and you like making websites.

Coast gives you a bunch of things that you normally wind up putting together yourself after a lot of searching, trying and failing. Integrating different libraries is really not something I wanted to spend my time on and I don't think you want to either. Let's say you want background jobs, you can look at the existing clojure background job libraries or use a language agnostic one, but you're already spending time not making your websites. That's not good! Use coast and jobs are built in, open your terminal in a folder with a coast app and type

coast gen jobs
make db/migrate
mkdir jobs
touch jobs/emails.clj

Edit jobs/emails.clj

(ns jobs.emails
  (:require []))

(defn send [email]
  (mailgun/send email)) ; or whatever you use for email

(defn queue [email]
  ( #'send email))

BOOM. You have a job that emails that you can use like this:

(require '[jobs.emails])

(jobs.emails/queue {:to "" :from "" :subject "subject" :body "body"})

Coast also has it's own built in worker that is currently pretty naive but can be started up with clj -m coast.worker

This guy emails!

Getting started with coast on clojure

Starting with coast on clojure is pretty easy, but I'm always open to suggestions.

Here's how you can start a simple web server with coast right now:

mkdir -p proj proj/src
touch proj/deps.edn
touch proj/src/server.clj
; deps.edn
{:paths ["src"]
 :deps {coast.gamma {:git/url ""
                     :sha "5242b6dcf6ca77b57de5b77f4dd47516ce459eff"}}}
; src/server.clj
(ns server
  (:require [coast.gamma :as coast]))

(defn hello [request]
  {:status 200
   :headers {"Content-Type" "text/html"}
   :body (str "hello " (-> request :params :name))})

(def routes [[:get "/hello/:name" hello]])

(def app (coast/app routes))

(coast/start-server app)

Then in your terminal, run:

clj src/server.clj &
# you should see => server is listening on port 1337
curl localhost:1337/hello/world
# you should see => hello world

There are so many nice little things in coast, I'm still taking the time to document them all, but rest assured, document them I will. I also improve the thing every month I make a new website, hopefully one of these days I'll nail the public facing api down and make one version that is backwards compatible until the end of time!

Stay tuned for more posts about coast!