all repos — litestore @ d031866fcb2675b000a856a3fb022b2e28522ba9

A minimalist nosql document store.

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
 47
 48
import jester, ../litestore, asyncdispatch, re, strtabs, asyncnet

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], request.params, 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)
    headers = newStringTable()
    for key, value in r.headers.pairs:
      headers[key] = value
    await response.sendHeaders(r.code, headers)
    response.client.close()

  options re"^\/litestore\/docs\/?(.*)":
    let r = options("docs", request.matches[0], request.headers)
    headers = newStringTable()
    for key, value in r.headers.pairs:
      headers[key] = value
    await response.sendHeaders(r.code, headers)
    response.client.close()

runForever()