Skip to content

planety/snowlight

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

starlight

Flask like web framework written in Nim.

Simple example

import starlight


var app = newApp(newSettings())

proc hello(ctx: Context) {.async, get(app, "/hello").} =
  resp "Hello world"

app.run()

Complex example

import starlight except loginPage
import htmlgen


func 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 "<h1>Hello, Prologue!</h1>"

proc home*(ctx: Context) {.async, route(app, "/home", HttpGet).} =
  resp "<h1>Home</h1>"

proc helloName*(ctx: Context) {.async, get(app, "/hello/{name}").} =
  resp "<h1>Hello, " & ctx.getPathParams("name", "Prologue!") & "</h1>"

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()

About

Flask like web framework written in Nim.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages