11# Merly.jl
22
3- * Micro framework for web programming in Julia.*
4-
5- [ ![ Build Status] ( https://travis-ci.org/codeneomatrix/Merly.jl.svg?branch=master )] ( https://travis-ci.org/codeneomatrix/Merly.jl )
6- [ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( https://raw.githubusercontent.com/codeneomatrix/Merly.jl/master/LICENSE.md )
7- [ ![ Merly] ( http://pkg.julialang.org/badges/Merly_0.4.svg )] ( http://pkg.julialang.org/?pkg=Merly )
8- [ ![ Merly] ( http://pkg.julialang.org/badges/Merly_0.5.svg )] ( http://pkg.julialang.org/?pkg=Merly )
9- [ ![ Merly] ( http://pkg.julialang.org/badges/Merly_0.6.svg )] ( http://pkg.julialang.org/?pkg=Merly )
10-
3+ <p align =" center " >
4+ <strong >Micro framework for web programming in Julia..</strong >
5+ <br ><br >
6+ <a href =" https://travis-ci.org/codeneomatrix/Merly.jl " ><img src =" https://travis-ci.org/codeneomatrix/Merly.jl.svg?branch=master " ></a >
7+ <a href =" https://codecov.io/gh/codeneomatrix/Merly.jl " >
8+ <img src =" https://codecov.io/gh/codeneomatrix/Merly.jl/branch/master/graph/badge.svg " />
9+ </a >
10+   ;  
11+ <a href =" https://pkg.julialang.org/detail/Merly " ><img src =" http://pkg.julialang.org/badges/Merly_0.6.svg " ></a >
12+ <a href =" https://pkg.julialang.org/detail/Merly " ><img src =" http://pkg.julialang.org/badges/Merly_0.7.svg " ></a >
13+   ;  ;
14+ <a href =" https://raw.githubusercontent.com/codeneomatrix/Merly.jl/master/LICENSE.md " ><img src =" https://img.shields.io/badge/license-MIT-blue.svg " ></a >
15+
16+ ## About
1117Merly is a micro framework for declaring routes and handling requests.
1218Quickly creating web applications in Julia with minimal effort.
1319
1420Roadmap
1521-----
16- 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.
22+ #### Version 0.0.3
23+ - [x] adding the debug option
24+ - [x] optimizing routes
25+ - [x] refactor notfount, cors, body
26+
27+ 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.
1728
1829### All contributions and suggestions are welcome !!!!
1930
2031#### Version 0.1.0
21- + Julia version 1.0 syntax update
22-
23- #### Version 0.1.1
24- + Implementation of verbose
32+ - [ ] Julia version 1.0 syntax update
2533
2634#### Version 0.1.2
27- + Implementation of a websocket module
28-
35+ - [ ] Implementation of a websocket module
36+
2937#### Version 0.1.3
30- + Performance improvement
31-
32- #### Version 0.1.4
33- + Threads implementation
34-
38+ - [ ] Performance improvement
39+
3540
3641Installing
3742----------
@@ -45,43 +50,42 @@ Pkg.clone("git://github.com/codeneomatrix/Merly.jl.git") #Development
4550``` julia
4651using Merly
4752
48- global u
4953u= " hello"
5054
5155server = Merly. app ()
5256
5357@page " /" " Hello World!"
54- @page " /hola/:usr" " <b>Hello {{usr}}!</b>"
58+ @page " /hola/:usr> " " <b>Hello {{usr}}!</b>"
5559
56- @route GET " /get/:data" begin
60+ @route GET " /get/:data> " begin
5761 " get this back: {{data}}"
5862end
5963
6064@route POST " /post" begin
61- " I did something!"
65+ res . data = " I did something!"
6266end
6367
6468@route POST| PUT| DELETE " /" begin
6569 println (" params: " ,q. params)
6670 println (" query: " ,q. query)
6771 println (" body: " ,q. body)
6872
69- r . headers[" Content-Type" ]= " text/plain"
73+ res . headers[" Content-Type" ]= " text/plain"
7074
7175 " I did something!"
7276end
7377
74- Get (" /data" , (q,r )-> (begin
75- r . headers[" Content-Type" ]= " text/plain"
76- " $u data"
78+ Get (" /data" , (q,req,res )-> (begin
79+ res . headers[" Content-Type" ]= " text/plain"
80+ u * " data"
7781end ))
7882
7983
80- Post (" /data" , (q,r )-> (begin
84+ Post (" /data" , (q,req,res )-> (begin
8185 println (" params: " ,q. params)
8286 println (" query: " ,q. query)
8387 println (" body: " ,q. body)
84- r . headers[" Content-Type" ]= " text/plain"
88+ res . headers[" Content-Type" ]= " text/plain"
8589 global u= " bye"
8690 " I did something!"
8791end ))
@@ -95,28 +99,32 @@ Features available in the current release
9599------------------
96100### Parameters dictionary
97101``` julia
98- @route GET " /get/:data" begin
102+ @route GET " /get/:data>" begin
103+ # matches "GET /get/foo" and "GET /get/bar"
104+ # q.params["data"] is 'foo' or 'bar'
99105 " get this back: " * q. params[" data" ]
100106end
101107```
102108### url query dictionary
109+
103110``` julia
104111@route POST| PUT| DELETE " /" begin
105- r. headers[" Content-Type" ]= " text/plain"
106-
107- " I did something! " * q. query[" value1name" ]
112+ res. headers[" Content-Type" ]= " text/plain"
113+ # matches "POST /?title=foo&author=bar"
114+ title = q. query[" title" ]
115+ author = q. query[" author" ]
116+ " I did something!"
108117end
109118```
110119### Dictionary of body
111120Payload
112121``` ruby
113- {" data1" :"Hello" }
122+ {" data1" :"Hello" }
114123```
115124``` julia
116125@route POST| PUT| DELETE " /" begin
117- r. headers[" Content-Type" ]= " text/plain"
118-
119- " Payload data " * q. body[" data1" ]
126+ res. headers[" Content-Type" ]= " text/plain"
127+ res. data = " Payload data " * q. body[" data1" ]
120128end
121129```
122130
@@ -128,8 +136,7 @@ Payload
128136```
129137``` julia
130138@route POST| PUT| DELETE " /" begin
131- r. headers[" Content-Type" ]= " text/plain"
132-
139+ res. headers[" Content-Type" ]= " text/plain"
133140 " Payload data " * q. body[" Data" ][" Data1" ]
134141end
135142```
@@ -138,21 +145,21 @@ end
138145
139146``` julia
140147@route POST| PUT| DELETE " /" begin
141- r . headers[" Content-Type" ]= " application/json"
142- r . status = 200 # optional
148+ res . headers[" Content-Type" ]= " application/json"
149+ res . status = 200 # optional
143150 " {\" data1\" :2,\" data2\" :\" t\" }"
144151end
145152
146153```
147154or
148155``` julia
149156@route POST| PUT| DELETE " /" begin
150- r . headers[" Content-Type" ]= " application/json"
157+ res . headers[" Content-Type" ]= " application/json"
151158 info= Dict ()
152159 info[" data1" ]= 2
153160 info[" data2" ]= " t"
154- r . status = 200 # optional
155- JSON. json (info)
161+ res . status = 200 # optional
162+ res . data = JSON. json (info)
156163end
157164
158165```
161168
162169``` julia
163170@route POST| PUT| DELETE " /" begin
164- r . headers[" Content-Type" ]= " application/xml"
171+ res . headers[" Content-Type" ]= " application/xml"
165172
166173 " <ListAllMyBucketsResult>
167174 <Buckets>
@@ -176,15 +183,26 @@ end
176183### Reply File
177184
178185``` julia
179- server = Merly . app ( " Path " , " load " ) # example: ("D:\\EXAMPLE\\src","*") defauld: (pwd()," ")
180- @page " / " File ( " Index.html " , r)
186+ @page " / " File ( " Index.html " )
187+ ```
181188
189+ ### Web server
190+
191+ ``` julia
192+ # By default, the location where to look for the files that will
193+ # be exposed will be the same where the script is, if the files are
194+ # not found in that site, the location of the files can be established
195+ # with the following instruction.
196+ server. webserverpath (" C:\\ path" ) # example in windows
197+
198+
199+ server. webserverfiles (" *" ) #
182200```
183201``` clojure
184- Possible values of load
185- " *" Load all the files located in the path, except what started with " ."
202+ Possible values of webserverfiles
203+
204+ " *" Load all the files located in the path, except what started with " ."
186205 " jl" ," clj|jl|py" Extension in files that will not be exposed
187- " " Any file, Default
188206```
189207
190208### Not found message
@@ -200,11 +218,11 @@ server.notfound("notfound.html")
200218```
201219### CORS
202220``` julia
203- server. use ( " CORS " )
221+ server. useCORS ( true )
204222```
205223
206224### Bonus
207225If you forgot the MIME type of a file you can use the next instruction
208226``` julia
209- r . headers[" Content-Type" ]= mimetypes[" file extension" ]
210- ```
227+ res . headers[" Content-Type" ]= mimetypes[" file extension" ]
228+ ```
0 commit comments