dummy-link

Merly

Micro framework for web programming in Julia

Readme

Merly.jl

Micro framework for web programming in Julia..

     

About

Merly is a micro framework for declaring routes and handling requests. Quickly creating web applications in Julia with minimal effort.

Roadmap

Version 0.0.3

  • [x] adding the debug option
  • [x] optimizing routes
  • [x] refactor notfount, cors, body

Below are some of the features that are planned to be added in future versions of Merly.jl once version 1.0 of the language is released.

All contributions and suggestions are welcome !!!!

Version 0.1.0

  • [ ] Julia version 1.0 syntax update

Version 0.1.2

  • [ ] Implementation of a websocket module

Version 0.1.3

  • [ ] Performance improvement

Installing

Pkg.add("Merly")                                           #Release
Pkg.clone("git://github.com/codeneomatrix/Merly.jl.git")   #Development

Example

using Merly

u="hello"

server = Merly.app()

@page "/" "Hello World!"
@page "/hola/:usr>" "Hello {{usr}}!"

@route GET "/get/:data>" begin
  "get this back: {{data}}"
end

@route POST "/post" begin
  res.data = "I did something!"
end

@route POST|PUT|DELETE "/" begin
  println("params: ",q.params)
  println("query: ",q.query)
  println("body: ",q.body)

  res.headers["Content-Type"]="text/plain"

  "I did something!"
end

Get("/data", (q,req,res)->(begin
  res.headers["Content-Type"]="text/plain"
  u*"data"
end))


Post("/data", (q,req,res)->(begin
  println("params: ",q.params)
  println("query: ",q.query)
  println("body: ",q.body)
  res.headers["Content-Type"]="text/plain"
  global u="bye"
  "I did something!"
end))


server.start("localhost", 8080)

Features available in the current release

Parameters dictionary

@route GET "/get/:data>" begin
  # matches "GET /get/foo" and "GET /get/bar"
  # q.params["data"] is 'foo' or 'bar'
  "get this back: "*q.params["data"]
end

url query dictionary

@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="text/plain"
  # matches "POST /?title=foo&author=bar"
  title = q.query["title"]
  author = q.query["author"]
  "I did something!"
end

Dictionary of body

Payload

{"data1":"Hello"}
@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="text/plain"
  res.data = "Payload data "*q.body["data1"]
end
``` html
Payload

Hello World!


```julia
@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="text/plain"
  "Payload data "*q.body["Data"]["Data1"]
end

Reply JSON

@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="application/json"
  res.status = 200 #optional
  "{\"data1\":2,\"data2\":\"t\"}"
end

or

@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="application/json"
  info=Dict()
  info["data1"]=2
  info["data2"]="t"
  res.status = 200 #optional
  res.data = JSON.json(info)
end

Reply XML

@route POST|PUT|DELETE "/" begin
  res.headers["Content-Type"]="application/xml"

  "
    
      quotes2006-02-03T16:45:09.000Z
      samples2006-02-03T16:41:58.000Z
    
  "
end

Reply File

@page "/" File("Index.html")

Web server

# By default, the location where to look for the files that will
# be exposed will be the same where the script is, if the files are
# not found in that site, the location of the files can be established
# with the following instruction.
server.webserverpath("C:\\path")  # example in windows


server.webserverfiles("*") #
Possible values of webserverfiles

 "*"               Load all the files located in the path, except what started with "."
 "jl","clj|jl|py"  Extension in files that will not be exposed
``` html
### Not found message

server.notfound(" Not found

404, Not found

")


```julia
server.notfound("notfound.html")

CORS

server.useCORS(true)

Bonus

If you forgot the MIME type of a file you can use the next instruction

res.headers["Content-Type"]=mimetypes["file extension"]

First Commit

01/17/2016

Last Touched

28 days ago

Commits

70 commits

Used By: