File-based router for ningle
Find a file
2024-02-14 01:46:42 +09:00
src Implement 2024-02-14 00:43:51 +09:00
.gitignore Setup lisp env 2024-02-13 16:32:48 +09:00
LICENSE Update README 2024-02-14 01:46:42 +09:00
ningle-fbr.asd Setup lisp env 2024-02-13 16:32:48 +09:00
qlfile Implement 2024-02-14 00:43:51 +09:00
qlfile.lock Implement 2024-02-14 00:43:51 +09:00
README.md Update README 2024-02-14 01:46:42 +09:00

ningle-fbr (WIP)

Plugin for ningle and jingle to enable file-based routing

Usage

To use ningle-fbr, you must use package-inferred-system.

/example.asd

(defsystem "example"
  :class :package-inferred-system
  :pathname "src"
  :depends-on ("example/app")

/src/app.lisp

(uiop:define-package #:example
  (:nicknames #:example/app)
  (:use #:cl)
  (:import-from #:ningle)
  (:import-from #:ningle-fbr))
(in-package #:example/app)

(defparameter *app* (make-instance 'ningle:<app>))

(defun update-routes ()
  (ningle-fbr:enable-file-based-routing
    *app*
    :dir "src/routes"
    :system "example"
    :system-pathname "src"))

(update-routes)

Static routing

/src/routes/index.lisp/

(uiop:define-package #:example/routes/index
  (:use #:cl)
  (:export #:on-get
           #:on-post
           #:on-put
           #:on-delete))
(in-package #:example/routes/index)

(defun on-get (params)
  ...)

(defun on-post (params)
  ...)

(defun on-put (params)
  ...)

(defun on-delete (params)
  ...)

Dynamic routing

A file or directory name prefixed with '=' indicates a dynamic path.

In the example below, the name parameter can be obtained from handler's params.

/src/routes/user/=name.lisp/user/:name

License

Licensed under MIT License. 

Copyright (c) 2024, skyizwhite.