The ningle Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The ningle Reference Manual

This is the ningle Reference Manual, version 0.3.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Apr 28 12:33:24 2020 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

ningle

Build Status

"ningle" is a lightweight web application framework for Common Lisp.

Usage

(defvar *app* (make-instance 'ningle:app))

(setf (ningle:route *app* "/")
      "Welcome to ningle!")

(setf (ningle:route *app* "/login" :method :POST)
      #'(lambda (params)
          (if (authorize (cdr (assoc "username" params :test #'string=))
                         (cdr (assoc "password" params :test #'string=)))
              "Authorized!"
              "Failed...Try again.")))

(clack:clackup *app*)

Now you can access to http://localhost:5000/ and then ningle should show you "Welcome to ningle!".

Installation

(ql:quickload :ningle)

Description

ningle is a fork project of Caveman. ningle doesn't require you to generate a project skeleton.

As this is a thin framework, you need to have subtle knowledge about Clack. It is a server interface ningle bases on.

Getting started

Routing

ningle has the Sinatra-like routing system.

;; GET request (default)
(setf (ningle:route *app* "/" :method :GET) ...)

;; POST request
(setf (ningle:route *app* "/" :method :POST) ...)

;; PUT request
(setf (ningle:route *app* "/" :method :PUT) ...)

;; DELETE request
(setf (ningle:route *app* "/" :method :DELETE) ...)

;; OPTIONS request
(setf (ningle:route *app* "/" :method :OPTIONS) ...)

Route pattern may contain "keyword" to put the value into the argument.

(setf (ningle:route *app* "/hello/:name")
      #'(lambda (params)
          (format nil "Hello, ~A" (cdr (assoc :name params)))))

The above controller will be invoked when you access to "/hello/Eitaro" or "/hello/Tomohiro", and then (cdr (assoc :name params)) will be "Eitaro" and "Tomohiro".

Route patterns may also contain "wildcard" parameters. They are accessible by (assoc :splat params).

(setf (ningle:route *app* "/say/*/to/*")
      #'(lambda (params)
          ; matches /say/hello/to/world
          (cdr (assoc :splat params)) ;=> ("hello" "world")
          ))

(setf (ningle:route *app* "/download/*.*")
      #'(lambda (params)
          ; matches /download/path/to/file.xml
          (cdr (assoc :splat params)) ;=> ("path/to/file" "xml")
          ))

Route matching with Regular Expressions:

(setf (ningle:route *app* "/hello/([\\w]+)" :regexp t)
      #'(lambda (params)
          (format nil "Hello, ~A!" (first (cdr (assoc :captures params))))))

Requirements

Routes may include a variety of matching conditions, such as the Accept:

(setf (ningle:route *app* "/" :accept '("text/html" "text/xml"))
      #'(lambda (params)
          (declare (ignore params))
          "<html><body>Hello, World!</body></html>"))

(setf (ningle:route *app* "/" :accept "text/plain")
      #'(lambda (params)
          (declare (ignore params))
          "Hello, World!"))

You can easily define your own conditions:

(setf (ningle:requirement *app* :probability)
      #'(lambda (value)
          (<= (random 100) value)))

(setf (ningle:route *app* "/win_a_car" :probability 10)
      #'(lambda (params)
          (declare (ignore params))
          "You won!"))

(setf (ningle:route *app* "/win_a_car")
      #'(lambda (params)
          (declare (ignore params))
          "Sorry, you lost."))

Request & Response

ningle provides two special variables named *request* and *response*. They will be bound to an instance Lack.Request and Lack.Response for each request.

For example, by using them, you can change the response status code, Content-Type or something like that in each controllers.

(setf (lack.response:response-headers *response*)
      (append (lack.response:response-headers *response*)
              (list :content-type "application/json")))

(setf (lack.response:response-headers *response*)
      (append (lack.response:response-headers *response*)
              (list :access-control-allow-origin "*")))

(setf (lack.response:response-status *response*) 201)

Context

ningle provides an useful function named context. It is an accessor to an internal hash table.

(setf (context :database)
      (dbi:connect :mysql
                   :database-name "test-db"
                   :username "nobody"
                   :password "nobody"))

(context :database)
;;=> #<DBD.MYSQL:<DBD-MYSQL-CONNECTION> #x3020013D1C6D>

Using Session

ningle doesn't provide Session system in the core, but recommends to use Lack.Middleware.Session with Lack.Builder.

(import 'lack.builder:builder)

(clack:clackup
  (builder
    :session
    *app*))

Of course, you can use other Lack Middlewares with ningle.

See Also

Author

Copyright

Copyright (c) 2012-2014 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the LLGPL License.


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Next: , Previous: , Up: Systems   [Contents][Index]

2.1 ningle

Author

Eitaro Fukamachi

License

LLGPL

Description

Super micro framework for Common Lisp.

Version

0.3.0

Dependencies
Source

ningle.asd (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.2 ningle/main

Author

Eitaro Fukamachi

License

LLGPL

Dependencies
Source

ningle.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.3 ningle/app

Author

Eitaro Fukamachi

License

LLGPL

Dependencies
Source

ningle.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.4 ningle/route

Author

Eitaro Fukamachi

License

LLGPL

Dependency

myway

Source

ningle.asd (file)

Component

lisp.lisp (file)


Previous: , Up: Systems   [Contents][Index]

2.5 ningle/context

Author

Eitaro Fukamachi

License

LLGPL

Source

ningle.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 ningle.asd

Location

ningle.asd

Systems

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 ningle/main/lisp.lisp

Parent

ningle/main (system)

Location

main.lisp

Packages

ningle


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 ningle/app/lisp.lisp

Parent

ningle/app (system)

Location

app.lisp

Packages

ningle/app

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.4 ningle/route/lisp.lisp

Parent

ningle/route (system)

Location

route.lisp

Packages

ningle/route

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.5 ningle/context/lisp.lisp

Parent

ningle/context (system)

Location

context.lisp

Packages

ningle/context

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 ningle

Source

lisp.lisp (file)

Nickname

ningle/main

Use List

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 ningle/app

Source

lisp.lisp (file)

Nickname

ningle.app

Use List

common-lisp

Used By List

ningle

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.3 ningle/route

Source

lisp.lisp (file)

Nickname

ningle.route

Use List

common-lisp

Exported Definitions
Internal Definitions

Previous: , Up: Packages   [Contents][Index]

4.4 ningle/context

Source

lisp.lisp (file)

Nickname

ningle.context

Use List

common-lisp

Used By List

ningle

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Special variables

Special Variable: *context*

Special variable to store Ningle Context, a hash table.
Don’t set to this variable directly. This is designed to be bound in lexical let.

Package

ningle/context

Source

lisp.lisp (file)

Special Variable: *request*

Special variable to store Ningle Request, a instance of ‘<request>’ in Ningle.Request package. Don’t set to this variable directly. This is designed to be bound in lexical let.

Package

ningle/context

Source

lisp.lisp (file)

Special Variable: *response*

Special variable to store Ningle Response, a instance of ‘<response>’ in Ningle.Response package. Don’t set to this variable directly. This is designed to be bound in lexical let.

Package

ningle/context

Source

lisp.lisp (file)

Special Variable: *session*

Special variable to store session.
Don’t set to this variable directly. This is designed to be bound in lexical let.

Package

ningle/context

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Macros

Macro: with-context-variables (&rest VARS) &body BODY
Package

ningle/context

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Functions

Function: clear-routing-rules APP
Package

ningle/app

Source

lisp.lisp (file)

Function: context &optional KEY

Access to current context. If key is specified, return the value in current context. If not, just return a current context.

Example:
(context)
;=> #<HASH-TABLE :TEST EQL size 0/60 #x3020025FF5FD>
(context :request)
;=> #<CAVEMAN.REQUEST:<REQUEST> #x3020024FCCFD>

Package

ningle/context

Source

lisp.lisp (file)

Writer

(setf context) (function)

Function: (setf context) VAL KEY
Package

ningle/context

Source

lisp.lisp (file)

Reader

context (function)

Function: make-context APP ENV

Create a new Context.

Package

ningle/context

Source

lisp.lisp (file)

Function: requirement APP NAME
Function: (setf requirement) FN APP NAME
Package

ningle/app

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Generic functions

Generic Function: make-request APP ENV

Make a request object. See ningle.app for the default behavior.

Package

ningle/context

Source

lisp.lisp (file)

Methods
Method: make-request (APP app) ENV

Make a request object. A class of the request object can be changed by overwriting this.

Source

lisp.lisp (file)

Generic Function: make-response APP &optional STATUS HEADERS BODY

Make a response object. See ningle.app for the default behavior.

Package

ningle/context

Source

lisp.lisp (file)

Methods
Method: make-response (APP app) &optional STATUS HEADERS BODY

Make a response object. A class of the response object can be changed by overwriting this.

Source

lisp.lisp (file)

Generic Function: not-found APP

An action when no routing rules are found.

Package

ningle/app

Source

lisp.lisp (file)

Methods
Method: not-found (THIS app)
Generic Function: process-response APP RESULT
Package

ningle/app

Methods
Method: process-response (APP app) RESULT
Source

lisp.lisp (file)

Generic Function: route APP STRING-URL-RULE &rest ARGS &key METHOD IDENTIFIER REGEXP &allow-other-keys
Generic Function: (setf route) CONTROLLER APP STRING-URL-RULE &rest ARGS &key METHOD IDENTIFIER REGEXP &allow-other-keys
Package

ningle/app

Source

lisp.lisp (file)

Methods
Method: route (THIS app) STRING-URL-RULE &rest ARGS &key METHOD IDENTIFIER REGEXP &allow-other-keys
Method: (setf route) CONTROLLER (THIS app) STRING-URL-RULE &rest ARGS &key METHOD IDENTIFIER REGEXP &allow-other-keys
Generic Function: route-controller OBJECT
Generic Function: (setf route-controller) NEW-VALUE OBJECT
Package

ningle/route

Methods
Method: route-controller (NINGLE-ROUTE ningle-route)

automatically generated reader method

Source

lisp.lisp (file)

Method: (setf route-controller) NEW-VALUE (NINGLE-ROUTE ningle-route)

automatically generated writer method

Source

lisp.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.5 Classes

Class: <app> ()

Base class for Ningle Application. All Ningle Application must inherit this class.

Package

ningle/app

Source

lisp.lisp (file)

Direct superclasses

lack-component (class)

Direct methods
Direct slots
Slot: mapper
Initform

(myway.mapper:make-mapper)

Readers

mapper (generic function)

Writers

(setf mapper) (generic function)

Slot: requirements
Type

hash-table

Initform

(ningle/app::default-requirements-map)

Readers

app-requirements (generic function)

Writers

(setf app-requirements) (generic function)

Class: app ()

Base class for Ningle Application. All Ningle Application must inherit this class.

Package

ningle/app

Source

lisp.lisp (file)

Direct superclasses

lack-component (class)

Direct methods
Direct slots
Slot: mapper
Initform

(myway.mapper:make-mapper)

Readers

mapper (generic function)

Writers

(setf mapper) (generic function)

Slot: requirements
Type

hash-table

Initform

(ningle/app::default-requirements-map)

Readers

app-requirements (generic function)

Writers

(setf app-requirements) (generic function)

Class: ningle-route ()
Package

ningle/route

Source

lisp.lisp (file)

Direct superclasses

route (class)

Direct methods
Direct slots
Slot: requirements
Initargs

:requirements

Initform

(quote nil)

Readers

route-requirements (generic function)

Writers

(setf route-requirements) (generic function)

Slot: compiled-requirements
Initargs

:compiled-requirements

Readers

route-compiled-requirements (generic function)

Writers

(setf route-compiled-requirements) (generic function)

Slot: controller
Initargs

:controller

Readers

route-controller (generic function)

Writers

(setf route-controller) (generic function)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: with-context (CONTEXT) &body BODY
Package

ningle/app

Source

lisp.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: compile-requirements MAP REQUIREMENTS
Package

ningle/route

Source

lisp.lisp (file)

Function: default-requirements-map ()
Package

ningle/app

Source

lisp.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Generic functions

Generic Function: app-requirements OBJECT
Generic Function: (setf app-requirements) NEW-VALUE OBJECT
Package

ningle/app

Methods
Method: app-requirements (APP app)

automatically generated reader method

Source

lisp.lisp (file)

Method: (setf app-requirements) NEW-VALUE (APP app)

automatically generated writer method

Source

lisp.lisp (file)

Generic Function: mapper OBJECT
Generic Function: (setf mapper) NEW-VALUE OBJECT
Package

ningle/app

Methods
Method: mapper (APP app)

automatically generated reader method

Source

lisp.lisp (file)

Method: (setf mapper) NEW-VALUE (APP app)

automatically generated writer method

Source

lisp.lisp (file)

Generic Function: route-compiled-requirements OBJECT
Generic Function: (setf route-compiled-requirements) NEW-VALUE OBJECT
Package

ningle/route

Methods
Method: route-compiled-requirements (NINGLE-ROUTE ningle-route)

automatically generated reader method

Source

lisp.lisp (file)

Method: (setf route-compiled-requirements) NEW-VALUE (NINGLE-ROUTE ningle-route)

automatically generated writer method

Source

lisp.lisp (file)

Generic Function: route-requirements OBJECT
Generic Function: (setf route-requirements) NEW-VALUE OBJECT
Package

ningle/route

Methods
Method: route-requirements (NINGLE-ROUTE ningle-route)

automatically generated reader method

Source

lisp.lisp (file)

Method: (setf route-requirements) NEW-VALUE (NINGLE-ROUTE ningle-route)

automatically generated writer method

Source

lisp.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   N  
Index Entry  Section

F
File, Lisp, ningle.asd: The ningle․asd file
File, Lisp, ningle/app/lisp.lisp: The ningle/app/lisp․lisp file
File, Lisp, ningle/context/lisp.lisp: The ningle/context/lisp․lisp file
File, Lisp, ningle/main/lisp.lisp: The ningle/main/lisp․lisp file
File, Lisp, ningle/route/lisp.lisp: The ningle/route/lisp․lisp file

L
Lisp File, ningle.asd: The ningle․asd file
Lisp File, ningle/app/lisp.lisp: The ningle/app/lisp․lisp file
Lisp File, ningle/context/lisp.lisp: The ningle/context/lisp․lisp file
Lisp File, ningle/main/lisp.lisp: The ningle/main/lisp․lisp file
Lisp File, ningle/route/lisp.lisp: The ningle/route/lisp․lisp file

N
ningle.asd: The ningle․asd file
ningle/app/lisp.lisp: The ningle/app/lisp․lisp file
ningle/context/lisp.lisp: The ningle/context/lisp․lisp file
ningle/main/lisp.lisp: The ningle/main/lisp․lisp file
ningle/route/lisp.lisp: The ningle/route/lisp․lisp file

Jump to:   F   L   N  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
A   C   D   F   G   M   N   P   R   W  
Index Entry  Section

(
(setf app-requirements): Internal generic functions
(setf app-requirements): Internal generic functions
(setf context): Exported functions
(setf mapper): Internal generic functions
(setf mapper): Internal generic functions
(setf requirement): Exported functions
(setf route): Exported generic functions
(setf route): Exported generic functions
(setf route-compiled-requirements): Internal generic functions
(setf route-compiled-requirements): Internal generic functions
(setf route-controller): Exported generic functions
(setf route-controller): Exported generic functions
(setf route-requirements): Internal generic functions
(setf route-requirements): Internal generic functions

A
app-requirements: Internal generic functions
app-requirements: Internal generic functions

C
clear-routing-rules: Exported functions
compile-requirements: Internal functions
context: Exported functions

D
default-requirements-map: Internal functions

F
Function, (setf context): Exported functions
Function, (setf requirement): Exported functions
Function, clear-routing-rules: Exported functions
Function, compile-requirements: Internal functions
Function, context: Exported functions
Function, default-requirements-map: Internal functions
Function, make-context: Exported functions
Function, requirement: Exported functions

G
Generic Function, (setf app-requirements): Internal generic functions
Generic Function, (setf mapper): Internal generic functions
Generic Function, (setf route): Exported generic functions
Generic Function, (setf route-compiled-requirements): Internal generic functions
Generic Function, (setf route-controller): Exported generic functions
Generic Function, (setf route-requirements): Internal generic functions
Generic Function, app-requirements: Internal generic functions
Generic Function, make-request: Exported generic functions
Generic Function, make-response: Exported generic functions
Generic Function, mapper: Internal generic functions
Generic Function, not-found: Exported generic functions
Generic Function, process-response: Exported generic functions
Generic Function, route: Exported generic functions
Generic Function, route-compiled-requirements: Internal generic functions
Generic Function, route-controller: Exported generic functions
Generic Function, route-requirements: Internal generic functions

M
Macro, with-context: Internal macros
Macro, with-context-variables: Exported macros
make-context: Exported functions
make-request: Exported generic functions
make-request: Exported generic functions
make-response: Exported generic functions
make-response: Exported generic functions
mapper: Internal generic functions
mapper: Internal generic functions
Method, (setf app-requirements): Internal generic functions
Method, (setf mapper): Internal generic functions
Method, (setf route): Exported generic functions
Method, (setf route-compiled-requirements): Internal generic functions
Method, (setf route-controller): Exported generic functions
Method, (setf route-requirements): Internal generic functions
Method, app-requirements: Internal generic functions
Method, make-request: Exported generic functions
Method, make-response: Exported generic functions
Method, mapper: Internal generic functions
Method, not-found: Exported generic functions
Method, process-response: Exported generic functions
Method, route: Exported generic functions
Method, route-compiled-requirements: Internal generic functions
Method, route-controller: Exported generic functions
Method, route-requirements: Internal generic functions

N
not-found: Exported generic functions
not-found: Exported generic functions

P
process-response: Exported generic functions
process-response: Exported generic functions

R
requirement: Exported functions
route: Exported generic functions
route: Exported generic functions
route-compiled-requirements: Internal generic functions
route-compiled-requirements: Internal generic functions
route-controller: Exported generic functions
route-controller: Exported generic functions
route-requirements: Internal generic functions
route-requirements: Internal generic functions

W
with-context: Internal macros
with-context-variables: Exported macros

Jump to:   (  
A   C   D   F   G   M   N   P   R   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
C   M   R   S  
Index Entry  Section

*
*context*: Exported special variables
*request*: Exported special variables
*response*: Exported special variables
*session*: Exported special variables

C
compiled-requirements: Exported classes
controller: Exported classes

M
mapper: Exported classes
mapper: Exported classes

R
requirements: Exported classes
requirements: Exported classes
requirements: Exported classes

S
Slot, compiled-requirements: Exported classes
Slot, controller: Exported classes
Slot, mapper: Exported classes
Slot, mapper: Exported classes
Slot, requirements: Exported classes
Slot, requirements: Exported classes
Slot, requirements: Exported classes
Special Variable, *context*: Exported special variables
Special Variable, *request*: Exported special variables
Special Variable, *response*: Exported special variables
Special Variable, *session*: Exported special variables

Jump to:   *  
C   M   R   S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   <  
A   C   N   P   S  
Index Entry  Section

<
<app>: Exported classes

A
app: Exported classes

C
Class, <app>: Exported classes
Class, app: Exported classes
Class, ningle-route: Exported classes

N
ningle: The ningle system
ningle: The ningle package
ningle-route: Exported classes
ningle/app: The ningle/app system
ningle/app: The ningle/app package
ningle/context: The ningle/context system
ningle/context: The ningle/context package
ningle/main: The ningle/main system
ningle/route: The ningle/route system
ningle/route: The ningle/route package

P
Package, ningle: The ningle package
Package, ningle/app: The ningle/app package
Package, ningle/context: The ningle/context package
Package, ningle/route: The ningle/route package

S
System, ningle: The ningle system
System, ningle/app: The ningle/app system
System, ningle/context: The ningle/context system
System, ningle/main: The ningle/main system
System, ningle/route: The ningle/route system

Jump to:   <  
A   C   N   P   S