Skip to content

A very lightweight web-framework for GNU Guile

Notifications You must be signed in to change notification settings

sniperpr/artanis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Artanis

Artanis aims to be a very lightweight web framework for Scheme which is written all with GNU Guile.

Features:

  • very lightweight: the core artanis.scm almost 300 lines, easy to hack and learn for newbies.
  • a relative complete web-server implementation, include error page throw and all the HTTP method (you have to specify your own handler)
  • 10K concurrent performance for the server, takes advantage of the Guile inner server. It's enough for you own site/blog.
  • sinatra like style route, that's why it names "artanis" ;-)
  • Database support (now use guile-dbi), mysql/sqlite/postgresql. But it's easy to port to other database binding. (but I like dbi)
  • session support
  • HTML template of SXML (very easy to use for Lisper)

INSTALL:

First, you need Guile-2.x: http://www.gnu.org/software/guile/ Or just install it with your apt-get/zypper/yum... I suggest you install Guile-2.0.7

You need guile-dbi to handle database: http://download.gna.org/guile-dbi/

And you need specified dbd to control the database, you have three choices:

  • guile-dbd-mysql
  • guile-dbd-postgresql
  • guile-dbd-sqlite3

All the database operations are in (artanis db).

NOTE: For our example/blog.scm, you need guile-dbd-mysql

All the packages above is easy to install:

  1. untar the package
  2. ./configure
  3. make
  4. sudo make install

Anyway, you don't have to install Artanis, you may just write your website under the artanis' toplevel directory. But if you like to install it, just copy/link artanis to somewhere like '/usr/local/share/guile/2.0' where guile was installed.

example:

It's very easy to use:

(init-server) ; make sure alway put it in the main script head.
(define my-var #f) ; a global var for later use

;; get means GET method in HTTP protocol, and you may use:
;; get/post/put/patch/delete
(get "/show-me" ; define a page which path named "show-me"
  (lambda (rc)  ; rc is route-context, you may do everything with it!
    (response-emit "OK, this is a hello world page!"))) 
;; any page must return with response-emit
   
(get "/show/:id" ; ":id" is a general key to indicate something you passed in
  (lambda (rc)
    (let ((id (params rc "id"))) ; use 'params' to get any key, include query-string
      (response-emit (format #f "the id is ~a" id)))))
;; now you may try "localhost:3000/show/123" in your fav browser, and it'll show
;; "the id is 123" in the page!

;; Why always 'get'? But 'get' is the most useful method of HTTP, anyway, you
;; may try others, like 'post':
(post "/edit/:name"
  (lambda (rc)
    (let ((name (params rc "name"))) ; ":name" means the key to specify is "name"
      (set! my-var name)
      (response-emit "edit name successfully!"))))

;; and just try to show the result you modified
(get "/show/name"
  (lambda (rc)
    (response-emit (format #f "the name is ~a" my-var))))

(run) ; the last line, you must run the inner server

Inner web server

The default port is 3000, so you have to fetch the URL like: http://localhost:3000/...

But you may specify it like this:

(run #:port 1234)

APIs docs

Coming soon...

Enjoy.

Happy hacking!

About

A very lightweight web-framework for GNU Guile

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published