Jump to content
Fi8sVrs

Merly.jl - Micro framework for web programming in Julia.

Recommended Posts

  • Active Members

Merly.jl

Micro framework for web programming in Julia.

 

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" "<b>Hello {{usr}}!</b>"

@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

Payload

<Data>
  <Data1>Hello World!</Data1>
</Data>

@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"

  "<ListAllMyBucketsResult>
    <Buckets>
      <Bucket><Name>quotes</Name><CreationDate>2006-02-03T16:45:09.000Z</CreationDate></Bucket>
      <Bucket><Name>samples</Name><CreationDate>2006-02-03T16:41:58.000Z</CreationDate></Bucket>
    </Buckets>
  </ListAllMyBucketsResult>"
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

Not found message

server.notfound("<!DOCTYPE html>
<html>
<head><title>Not found</title></head>
<body><h1>404, Not found</h1></body>
</html>")
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"]

Download: Merly.jl-master.zip

or

git clone https://github.com/codeneomatrix/Merly.jl.git

 

Source: https://github.com/codeneomatrix/Merly.jl

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...