all repos — litestore @ 57a4a616c9824be24be31e70fa943c45b4cb4f10

A minimalist nosql document store.

src/litestorepkg/examples/jester_integration.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
import jester, ../litestore, asyncdispatch, re, strtabs, asyncnet, sequtils

litestore.setup()

routes:

  # Just a simple, unrelated Jester route
  get "/":
    resp "Hello, World!"

  # Remapping LiteStore routes on Jester
  get re"^\/litestore\/(docs|info)\/?(.*)":
    let r = get(request.matches[0], request.matches[1], newStringTable(toSeq(request.params.pairs)), request.headers)
    resp(r.code, r.content, r.headers["Content-Type"])

  post re"^\/litestore\/docs\/?(.*)":
    let r = post("docs", request.matches[0], request.body, request.headers)
    resp(r.code, r.content, r.headers["Content-Type"])

  put re"^\/litestore\/docs\/?(.*)":
    let r = put("docs", request.matches[0], request.body, request.headers)
    resp(r.code, r.content, r.headers["Content-Type"])

  patch re"^\/litestore\/docs\/?(.*)":
    let r = patch("docs", request.matches[0], request.body, request.headers)
    resp(r.code, r.content, r.headers["Content-Type"])

  delete re"^\/litestore\/docs\/?(.*)":
    let r = delete("docs", request.matches[0], request.headers)
    resp(r.code, r.content)

  head re"^\/litestore\/docs\/?(.*)":
    let r = head("docs", request.matches[0], request.headers)
    var headers: RawHeaders = newSeq[tuple[key: string, val: string]]()
    for key, val in r.headers.pairs:
      headers.add({key: key, val: val})
    sendHeaders(request, r.code, headers)

  options re"^\/litestore\/docs\/?(.*)":
    let r = options("docs", request.matches[0], request.headers)
    var headers: RawHeaders = newSeq[tuple[key: string, val: string]]()
    for key, val in r.headers.pairs:
      headers.add({key: key, val: val})
    sendHeaders(request, r.code, headers)

runForever()