0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Juliaの「Merly」のExampleを見ながら動かしてみる

Posted at

JuliaのMerlyというマイクロフレームワークを使ってみた。
codeneomatrix/Merly.jl: Micro framework for web programming in Julia
READMEにExampleがついているので、これを動かしてみる。

Install

Pkgでインストールする。
インストールすると 0.2.1 というバージョンが入るが、このタグは2019年に作られたもので、古くなっている。
なので、masterブランチを指定してインストールする。

pkg> add Marly#master

READMEのExampleを見ながら動かす

以下をREPLにコピペするか、jlファイルに書き込みjuliaコマンドで実行する。

using Merly

# page: GETリクエストに対応したルートを設定する
@page "/" "Hello World!"
@page "/hello/:usr>" "<b>Hello {{usr}}!</b>"

# route: 第1引数に指定したリクエストに対応したルートを設定する
# 「|」で区切ると複数同時に設定可能
@route GET "/get/:data>" begin
  "get this back: {{data}}"
end

@route POST "/post" begin
  println(req.body)
  res.body = "I did something"
end

@route POST|PUT|DELETE "/" begin
  println(req)

  "I did something!"
end

# GET, POST, PUT, DELETE: それぞれに対応したルートを設定する
# reqest, responseを無名関数の引数に指定できる
Get("/data", (req, res)->(begin
  res.headers["Content-Type"] = "text/plain"
  "You Got"
end))

start(port=1234)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?