moclojer
GitHub
  • README
  • First Steps
    • Overview
    • Installation
    • Your First Mock Server
    • Dynamic Responses
    • Multiple Endpoints
    • Real-World Example
  • Templates
    • Template System Overview
    • Template Variables
  • Advanced Features
    • WebSocket Support
    • External Bodies
    • Webhook Integration
    • Rate Limiting
    • Multi-Domain Support
  • Framework Integration
    • Using as a Library
  • Reference Documentation
    • Configuration Specification
    • FAQ
  • Community and Contribution
    • Documentation Refactor
    • Code of Conduct
  • Release Notes
    • Latest Changes
    • v0.4.0
    • v0.3.5
    • v0.3.4
    • v0.3.3.1
    • v0.3.3
    • v0.3.2
    • v0.3.1
    • v0.3.0
    • v0.2
    • v0.1
Powered by GitBook
On this page
  • Where to start?
  • Distribution
  • Clojure CLI/deps.edn
  • Leiningen/Boot
  • git in deps.edn
  • Example

Was this helpful?

Edit on GitHub
  1. Framework Integration

Using as a Library

Moclojer supports use as a library (package), making it possible to import and extend standard behavior

Do you know when you want to use (binary) software, but you miss a feature that doesn't yet exist in its core (or the maintainers believe it doesn't make sense to implement)? With this in mind, moclojer makes it possible to extend its default behavior by using it as a library, importing the packages you need and changing the default behavior.

Where to start?

moclojer consists of two main features:

  • specification for writing http configuration

  • http server (we use pedestal)

The specification is the main feature of moclojer, and it is the one that allows you to write the configuration of the http server in a simple and intuitive way.

Distribution

We distribute the library via Clojars.

Clojure CLI/deps.edn

com.moclojer/moclojer {:mvn/version "0.3.1"}

Leiningen/Boot

[com.moclojer/moclojer "0.3.1"]

git in deps.edn

{:deps
 {com.moclojer/moclojer {:git/url "https://github.com/moclojer/moclojer.git"
                         :git/tag "v0.3.1"
                         :git/sha "c4ca0f2cfcfbe47de6eb0c601b26106190e20793"}}}

Example

(ns my-app.core
  (:require [com.moclojer.adapters :as adapters]
            [com.moclojer.server :as server]))

(def *router
  "create a router from a config map"
  (adapters/generate-routes
   [{:endpoint
     {:method "GET"
      :path "/example"
      :response {:status 200
                 :headers {:Content-Type "application/json"}
                 :body {:id 123}}}}]))

(defn -main
  "start the server"
  [& args]
  (server/start-server! *router))
PreviousMulti-Domain SupportNextConfiguration Specification

Last updated 1 year ago

Was this helpful?