rkdora's Blog

SchemeでWebアプリを開発できるらしい #1

準備

raco pkg install https://github.com/dmac/spin.git
詳細は、こちら↓

github.com

コード

#lang racket

(require (planet dmac/spin))

(define header "<h1>Wellcome to my page</h1>")

(define footer "<hr> &copy; ryuto")

(define html
  (lambda (s)
    (format "~a~a~a" header s footer)))

(get "/"
  (lambda (req)
    (html "
      <h2>My name is Ryuto!</h2>
      <a href='/hello'>Hello!</a>
    ")))

(get "/hello"
  (lambda (req)
    (html "
      <h2>Hello!</h2>
      <a href='/'>home</a>
    ")))

(run)

動作

racket index.rktでサーバー起動。
localhost:8000にアクセスすると、、、
f:id:rkdora:20190614173545p:plain

「Hello!」というリンクを踏むと、、、 f:id:rkdora:20190614173629p:plain

おおおおおおおお、たった一つのファイルで。。。

感想

railsみたく、自動生成されるものが無いためとてもコンパクトに開発ができそう。
しかし、規模が大きいものには不向きな気もする。
引き続き遊ぶ。

一応、githubにもあげといた。

github.com


続く

rkdora.hatenablog.com