/cjweb

Primary LanguageClojureEclipse Public License 1.0EPL-1.0

cjweb

A Clojure application designed to get you quickly ramped up with a running Web Server that exposes a dynamic CRUD rest api to your mongo database.

This is a great tool for prototyping backend json data for front end web applications.

This application does not contain any security and runs on http://localhost:8080 it also uses the default mongo connection properties "127.0.0.1" port 27017

Dependencies

  1. Java JRE 8
  2. Mongo DB
  3. Clojure
  4. Leiningen

Usage

from the command line

lein repl
user=> (load "cjweb/core")
user=> (ns cjweb.core)
cjweb.core=> (start-server)

You can now browse to your application

Example

Create

The below curl will create a database called library and a collection called book.

It will also store a book record represented by the json in the book collection of your mongo db.

from the command line

Mac

curl -d '{"title":"Learning clojure","isbn":"3424","author":"Alex Mcknight"}' -H "Content-Type: application/json" -X POST  http://localhost:8080/mongo/library/book

Windows

curl -d "{\"title\":\"Learning clojure\",\"isbn\":\"3424\",\"author\":\"Alex Mcknight\"}" -H "Content-Type: application/json" -X POST  http://localhost:8080/mongo/library/book

Searching

optional parameters

page = what page of the data should we retrieve

rows = how many records of the data should we retrieve

q = the valid mongo json query

curl -H "Content-Type: application/json" -X GET  http://localhost:8080/mongo/library/book?page=1&rows=10&q={"title":{"bw":"Learn"}}

Update

Update is the same as save except that an id must be included that references the record in question

curl -d '{"_id":"ID_OF_THE_RECORD",title":"Learning clojure","isbn":"3424","author":"Alexander Mcknight"}' -H "Content-Type: application/json" 

Get by ID

curl -H "Content-Type: application/json" -X GET  http://localhost:8080/mongo/library/book/ID_OF_THE_RECORD

Remove by ID

curl -H "Content-Type: application/json" -X DELETE http://localhost:8080/mongo/library/book/ID_OF_THE_RECORD

Testing

from the command line

lein test 

License

Copyright © 2019

Distributed under the Eclipse Public License (the same as Clojure) or the Apache Public License 2.0.