all repos — litestore @ 1472fe10c3ef43e00dc95c85b03bbfb7a29adf9e

A minimalist nosql document store.

Fixed nim API issues.
h3rald h3rald@h3rald.com
Fri, 13 Oct 2017 20:46:15 +0200
commit

1472fe10c3ef43e00dc95c85b03bbfb7a29adf9e

parent

65e41a25724549f49667362c0574eea78ebdda99

4 files changed, 28 insertions(+), 28 deletions(-)

jump to
M examples/jester_integration.nimexamples/jester_integration.nim

@@ -10,31 +10,31 @@ resp "Hello, World!"

# Remapping LiteStore routes on Jester get re"^\/litestore\/(docs|info)\/?(.*)": - let r = get(request.matches[0], request.matches[1], request.params) + 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) + 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) + 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) + 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]) - resp(r.code, r.content, r.headers["Content-Type"]) + 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]) - resp(r.code, r.content, r.headers["Content-Type"]) + let r = head("docs", request.matches[0], request.headers) + resp(r.code, r.content) options re"^\/litestore\/docs\/?(.*)": - let r = options("docs", request.matches[0]) - resp(r.code, r.content, r.headers["Content-Type"]) + let r = options("docs", request.matches[0], request.headers) + resp(r.code, r.content) runForever()
M lib/api_v2.nimlib/api_v2.nim

@@ -221,7 +221,7 @@ result.code = Http200

proc postDocument*(LS: LiteStore, body: string, ct: string, folder=""): LSResponse = if not folder.isFolder: - return resError(Http400, "Invalid folder specified when creating document: $folder" % folder) + return resError(Http400, "Invalid folder specified when creating document: $1" % folder) try: var doc = LS.store.createDocument(folder, body, ct) if doc != "":
M lib/utils.nimlib/utils.nim

@@ -16,7 +16,7 @@ contenttypes,

logger proc isFolder*(id: string): bool = - return (id.len > 0 and id[id.len-1] == '/') + return (id.len == 0 or id.len > 0 and id[id.len-1] == '/') proc dbQuote*(s: string): string = result = "'"
M litestore.nimlitestore.nim

@@ -89,10 +89,10 @@ for key, value in pairs(table):

params.add("$1=$2" % @[key, value.encodeUrl]) return params.join("&") - proc newLSRequest(meth: HttpMethod, resource, id, body = "", params = newStringTable()): LSRequest = + proc newLSRequest(meth: HttpMethod, resource, id, body = "", params = newStringTable(), headers = newHttpHeaders()): LSRequest = result.reqMethod = meth result.body = body - result.headers = newHttpHeaders() + result.headers = headers result.url = parseUri("$1://$2:$3/$4/$5?$6" % @["http", "localhost", "9500", resource, id, params.query()]) # Public API: Low-level

@@ -123,23 +123,23 @@ return LS.patchDocument(id, body)

# Public API: High-level - proc get*(resource, id: string, params = newStringTable()): LSResponse = - return newLSRequest(HttpGet, resource, id, "", params).get(LS, resource, id) + proc get*(resource, id: string, params = newStringTable(), headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpGet, resource, id, "", params, headers).get(LS, resource, id) - proc post*(resource, id, body: string): LSResponse = - return newLSRequest(HttpPost, resource, id, body).post(LS, resource, id) + proc post*(resource, id, body: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpPost, resource, id, body, newStringTable(), headers).post(LS, resource, id) - proc put*(resource, id, body: string): LSResponse = - return newLSRequest(HttpPut, resource, id, body).put(LS, resource, id) + proc put*(resource, id, body: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpPut, resource, id, body, newStringTable(), headers).put(LS, resource, id) - proc patch*(resource, id, body: string): LSResponse = - return newLSRequest(HttpPatch, resource, id, body).patch(LS, resource, id) + proc patch*(resource, id, body: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpPatch, resource, id, body, newStringTable(), headers).patch(LS, resource, id) - proc delete*(resource, id: string): LSResponse = - return newLSRequest(HttpPatch, resource, id).delete(LS, resource, id) + proc delete*(resource, id: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpPatch, resource, id, "", newStringTable(), headers).delete(LS, resource, id) - proc head*(resource, id: string): LSResponse = - return newLSRequest(HttpHead, resource, id).head(LS, resource, id) + proc head*(resource, id: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpHead, resource, id, "", newStringTable(), headers).head(LS, resource, id) - proc options*(resource, id: string): LSResponse = - return newLSRequest(HttpOptions, resource, id).options(LS, resource, id) + proc options*(resource, id: string, headers = newHttpHeaders()): LSResponse = + return newLSRequest(HttpOptions, resource, id, "", newStringTable(), headers).options(LS, resource, id)