Code Monkey home page Code Monkey logo

merly.jl's Introduction

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.

All contributions and suggestions are welcome !!!!

Installing

(@v1.5) pkg> add Merly

Example

using Merly
using JSON

u = 1

function tojson(data::String)
   return JSON.parse(data)
end

formats["application/json"] = tojson

@page "/" HTTP.Response(200,"Hello World!")
@page "/hola/:usr" (;u=u) HTTP.Response(200,string("<b>Hello ",request.params["usr"],u,"!</b>"))

@route GET "/get/:data1" (;u=u) begin
  u = u +1
  HTTP.Response(200, string(u ,request.params["data1"]))
end

@route POST "/post" begin
  HTTP.Response(200,"I did something!")
end

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

  HTTP.Response(200
          , HTTP.mkheaders(["Content-Type" => "text/plain"])
          , body="I did something2!")
end

Get("/data", (request,HTTP)->begin

  println("params: ",request.params)
  println("query: ",request.query)

  HTTP.Response(200
          , HTTP.mkheaders(["Content-Type" => "text/plain"])
          , body=string(u,"data ", get(request.query,"hola","")))

end)


Post("/data", (request,HTTP)-> begin
  println("params: ",request.params)
  println("query: ",request.query)
  println("body: ",request.body)

  global u="bye"

  HTTP.Response(200
          , HTTP.mkheaders(["Content-Type" => "text/plain"])
          , body=string("I did something! ", request.body["query"]))

end)


start(host = "127.0.0.1", port = 8086, verbose = true)

merly.jl's People

Contributors

juliatagbot avatar neomatrixcode avatar phelipe avatar staticfloat avatar tkelman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

merly.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

"File not working"

Describe the bug
@page "/" File("Index.html") is not working, it trows

┌ Error: error handling request
│   exception =
│    UndefVarError: File not defined

To Reproduce
Steps to reproduce the behavior:

  1. Set up environment
  2. Arguments
  3. Function/method
  4. See error

Expected behavior
Load the html page

Environment

  • Repository
  • OS: Manaro Linux
  • REPL

Merly Architecture

Hi, I am exploring web server's for Julia to serve results from a deep neural network written in Julia. I love that Merly's style is in the tradition of Flask: declarative and simple.

I'd like to know about Merly's internal like

  • Is it based on a Middleware framework?
  • Is is asynchronous or uses "green threads"?
  • How well does it scale?
  • Is it compatible with the latest Julia?

Thanks!

bug

error al procesar los siguientes parámetros:

?lat=17.0637447&lon=-96.7253164&accuracy=100&countryCode=**&lang=en&phoneId=dummyPhone&version=8.4&radius=1500

"ERROR: UndefVarError: start not defined" with readme example

Describe the bug
UndefVarError is thrown when running README Example.
app = Merly.app(); app.start() is working.
How can I use start method ?

To Reproduce
Steps to reproduce the behavior:

Run below on julia repl

using Merly

u="hello"

@page "/" "Hello World!"
@page "/hello/:usr>" "<b>Hello {{usr}}!</b>"

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

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

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

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

  "I did something!"
end

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


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


start(verbose = false)

Expected behavior
Run Merly app without Error.

Environment

  • Julia: v1.5.0
  • OS: macOS v10.14.6
  • IDE: REPL

UndefVarError on imports when using @route

Describe the bug
I get a "variable not defined" error from both the Redis and Formatting packages when using @route GET "/url" but not when using Get("/url", (res, req)). I prefer the @route syntax so it's slightly inconvenient for me.

To Reproduce
Steps to reproduce the behavior:

using Merly, Redis, Formatting

server = Merly.app()
conn = RedisConnection()

@route GET "/test-redis" begin
    res.body = Redis.get(conn, "key")
end

@route GET "/test-format" begin
    res.body = Formatting.format("Hello {:s}", "world")
end

server.start()
curl -v "http://localhost:8000/test-redis"
curl -v "http://localhost:8000/test-format"

Expected behavior
A GET route that can connect to a Redis database or format a string. Instead get "UndefVarError: Redis not defined". I also tested HTTP and JSON packages and they are both defined when using @route.

Environment

  • OS: Ubuntu and Fedora both do this

Benchmarks?

This is an AWESOME project. Thank you so much for writing it! 👍 I just found it and ripped out some of the code to use in a similar julia microframework (with a radically different routing engine)

Have you written any benchmarks for Merly's routing? If you haven't and I find some time, I'll try to share some back with you. If you're interested in working on that, we can pair program if you'd like. 😈

CORS

I tried using

server.use ("CORS")

but it is only working for GET requests,
CORS do not work with POST requests

@route GET "/get" begin
  "get this back: "
end

@route POST "/get" begin
  "get this back: "
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.