Coder Social home page Coder Social logo

artanis's Introduction

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!

artanis's People

Contributors

mario-goulart avatar nalaginrut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.