ver 1.0.1
![nimble](https://raw.githubusercontent.com/yglukhov/nimble-tag/master/nimble.png)
This is a plugin for the nim web framework Jester. It creates a JSON object document and pre-embeds key information such as the request details.
- Include the plugin
j <- jsonDefault()
at the top of your mainroutes
or primaryrouter
. This will enable the plugin for the whole web site. - In every route, the JsonNode variable created by the plugin is available.
import json
import jester
import jesterjson
proc namePage(j: JsonNode): string =
if j["request"]["params"].hasKey("name"):
result = "Hello " & j["request"]["params"]["name"].getStr
else:
result = "Hello stranger"
routes:
plugin j <- jsonDefault()
get "/test": # get http://127.0.0.1/test?name=Joe
resp namePage(j)
A new JsonNode object is created and the following keys are setup in it:
j["request"] contains a subset of the request variable. Specifically:
- j["request"]["params"] is an object contains names/values of the parameters
- j["request"]["port"] is an integer indicating the port the request came in on
- j["request"]["host"] is a string of the host name used to make the request
- j["request"]["secure"] is a boolean indicating HTTPS usage or not
- j["request"]["path"] is a string of the requests URL path name
- j["request"]["path"] is a string describing the request method (post, get, put, etc.)
j["env"] is an object of the OS environment variables
j["commandLineParams"] contains an array of the parameters passed to the server on startup
j["encodedUrl"] is a base-64 hex string of the URL. Sometimes that is useful for tracking and redirection.
j["currentTime"] is a string contains a
Time
parsable version of the current time and datej["rfc2822"] is a string with current Time in RFC 2822 format. See https://www.ietf.org/rfc/rfc2822.txt
Appendices