Code Monkey home page Code Monkey logo

usermanager-example's Introduction

Example Web Application in Clojure

This is a simple web application using Component, Ring, Compojure, and Selmer connected to a local SQLite database.

Clojure beginners often ask for a "complete" example that they can look at to see how these common libraries fit together and for a long time I pointed them at the User Manager example in the Framework One for Clojure repo -- but since I EOL'd that framework and I'd already rewritten the example app to no longer use the framework, it's just confusing to point them there, so this is a self-contained repo containing just that web app example.

A variant using Integrant and Reitit (instead of Component and Compojure), inspired by this example repo, can be found in Michaël Salihi's repo.

A version of this application that uses the Polylith architecture is also available, on the polylith branch.

Requirements

This example assumes that you have a recent version of the Clojure CLI installed (at least 1.10.1.727), and provides a deps.edn file.

Clojure 1.10 (or later) is required. The "model" of this example app uses namespace-qualified keys in hash maps. It uses next.jdbc -- the "next generation" JDBC library for Clojure -- which produces namespace-qualified hash maps from result sets.

Usage

Clone the repo, cd into it, then follow below to Run the Application or Run the application in REPL or Run the tests.

Run the Application

clj -M -m usermanager.main

It should create a SQLite database (usermanager_db) and populate two tables (department and addressbook) and start a Jetty instance on port 8080.

If that port is in use, start it on a different port. For example, port 8100:

clj -M -m usermanager.main 8100

Run the Application in REPL

Start REPL

$ clj

Once REPL starts, start the server as an example on port 8888:

user=> (require 'usermanager.main)                             ; load the code
user=> (in-ns 'usermanager.main)                               ; move to the namesapce
usermanager.main=> (def system (new-system 8888))              ; specify port
usermanager.main=> (alter-var-root #'system component/start)   ; start the server

Run the tests with:

clj -X:test:runner

There aren't any tests yet but I will create some soon!

Stuff I Need To Do

  • There should be some real-world tests.
  • I might add a datafy/nav example.

License & Copyright

Copyright (c) 2015-2021 Sean Corfield.

Distributed under the Apache Source License 2.0.

usermanager-example's People

Watchers

 avatar

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.