Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/planety/snowlight
Flask like web framework written in Nim.
https://github.com/planety/snowlight
Last synced: 3 months ago
JSON representation
Flask like web framework written in Nim.
- Host: GitHub
- URL: https://github.com/planety/snowlight
- Owner: planety
- License: apache-2.0
- Created: 2020-04-30T00:18:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-16T15:20:45.000Z (about 4 years ago)
- Last Synced: 2024-04-13T21:01:19.252Z (7 months ago)
- Language: Nim
- Homepage:
- Size: 15.6 KB
- Stars: 24
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - starlight - Flask-like web framework written in Nim. (Web / Frameworks)
README
# starlight
Flask like web framework written in Nim.## Simple example
```nim
import starlightvar app = newApp(newSettings())
proc hello(ctx: Context) {.async, get(app, "/hello").} =
resp "Hello world"app.run()
```## Complex example
```nim
import starlight except loginPage
import htmlgenfunc loginPage*(): string =
return html(form(action = "/login",
`method` = "post",
"Username: ", input(name = "username", `type` = "text"),
"Password: ", input(name = "password", `type` = "password"),
input(value = "login", `type` = "submit")),
xmlns = "http://www.w3.org/1999/xhtml")var app = newApp(newSettings())
proc hello*(ctx: Context) {.async,
get(app, "/"),
post(app, "/"),
get(app, "/hello")
.} =
resp "Hello, Prologue!
"proc home*(ctx: Context) {.async, route(app, "/home", HttpGet).} =
resp "Home
"proc helloName*(ctx: Context) {.async, get(app, "/hello/{name}").} =
resp "Hello, " & ctx.getPathParams("name", "Prologue!") & "
"proc redirectHome*(ctx: Context) {.async, route(app, "/redirect").} =
resp redirect("/home")proc loginGet*(ctx: Context) {.async, route(app, "/loginget").} =
resp loginGetPage()proc doLoginGet*(ctx: Context) {.async, route(app, "/loginpage", [HttpGet, HttpPost]).} =
resp redirect("/hello/Nim")proc login*(ctx: Context) {.async, get(app, "/login").} =
resp loginPage()proc doLogin*(ctx: Context) {.async, post(app, "/login").} =
resp redirect("/hello/Nim")app.run()
```