Giter Club home page Giter Club logo

moclojer's Introduction

moclojer

linter tests

moclojer -  Simple and efficient HTTP mock server with easy spec | Product Hunt

Simple and efficient HTTP mock server with specification written in yaml, edn or OpenAPI.

๐Ÿ’พ Download the .jar file with the latest version of moclojer to test on your computer here.

๐Ÿ“– See the complete documentation for moclojer here, if you want to contribute (or complement) the documentation, it is here.

YAML example

# This mock register route: GET /hello/:username
- endpoint:
    # Note: the method could be omitted because GET is the default
    method: GET
    path: /hello/:username
    response:
      # Note: the status could be omitted because 200 is the default
      status: 200
      headers:
        Content-Type: application/json
      # Note: the body will receive the value passed in the url using the
      # :username placeholder
      body: >
        {
          "hello": "{{path-params.username}}!"
        }

docker

  • image: ghcr.io/moclojer/moclojer:latest
  • port (default): 8000, if you want to change the port set the environment variable PORT
docker run -it \
  -p 8000:8000 -v $(pwd)/moclojer.yml:/app/moclojer.yml \
  ghcr.io/moclojer/moclojer:latest

we Two available versions:

  • dev: main branch docker image
  • latest: latest stable version image

manual installation

We distribute via the .jar file, you need to have Java installed on your operating system.

bash < <(curl -s https://raw.githubusercontent.com/moclojer/moclojer/main/install.sh)

If you are using Linux you maybe need sudo.

CLI Usage

  • clj -M:run [OPTIONS]
  • java -jar moclojer.jar [OPTIONS]
  • moclojer_Linux [OPTIONS]

Options

parameter description
-c, --config Config path or the CONFIG environment variable. [default: ~/.config/moclojer.yml]
-m, --mocks OpenAPI v3 mocks path or the MOCKS environment variable.
-f, --format Output and logging format. Either println or json.
-h, --help Show help information
-v, --version Show version information

sentry: set environment var SENTRY_DSN (sentry doc), automatic send backtrace to <sentry.io>

Config uses XDG_CONFIG_HOME to fetch the default moclojer configuration file, if you want to set a different directory you must use the -c or environment variable CONFIG

๐Ÿ’ป dev environment

moclojer is written in Clojure, to run the commands below we assume you have clojure installed on your operating system.

run:

clj -M:run

test:

clj -M:test

if you want to run a specific test: clj -M:test -n com.moclojer.external-body.excel-test

moclojer.jar generate:

clj -A:dev -M --report stderr -m com.moclojer.build

framework integrations

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 of use

(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))

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.