dummy-link

Merly

Micro framework for web programming in Julia

Readme

Merly.jl

Micro framework for web programming in Julia.

Build Status GitHub license Merly Merly Merly

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

Roadmap

Below are some of the features that are planned to be added in future versions of Faker.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.1

  • Implementation of verbose

Version 0.1.2

  • Implementation of a websocket module

Version 0.1.3

  • Performance improvement

Version 0.1.4

  • Threads implementation

Installing

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

Example

using Merly

global u
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
  "I did something!"
end

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

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

  "I did something!"
end

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


Post("/data", (q,r)->(begin
  println("params: ",q.params)
  println("query: ",q.query)
  println("body: ",q.body)
  r.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
  "get this back: "*q.params["data"]
end

url query dictionary

@route POST|PUT|DELETE "/" begin
  r.headers["Content-Type"]="text/plain"

  "I did something! "*q.query["value1name"]
end

Dictionary of body

Payload

{"data1":"Hello"}  
@route POST|PUT|DELETE "/" begin
  r.headers["Content-Type"]="text/plain"

  "Payload data "*q.body["data1"]
end
``` html
Payload

Hello World!


```julia
@route POST|PUT|DELETE "/" begin
  r.headers["Content-Type"]="text/plain"

  "Payload data "*q.body["Data"]["Data1"]
end

Reply JSON

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

or

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

Reply XML

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

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

Reply File

server = Merly.app("Path","load") #example: ("D:\\EXAMPLE\\src","*")  defauld: (pwd(),"")
@page "/" File("Index.html", r)
Possible values of load
 "*"              Load all the files located in the path, except what started with "."
 "jl","clj|jl|py"  Extension in files that will not be exposed
 ""               Any file, Default
``` html
### Not found message

server.notfound(" Not found

404, Not found

")


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

CORS

server.use("CORS")

Bonus

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

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

First Commit

01/17/2016

Last Touched

23 days ago

Commits

55 commits

Used By: