{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/9","labels_url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/9/comments","events_url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/9/events","html_url":"https://github.com/JuliaWeb/Roadmap/issues/9","id":106264470,"number":9,"title":"Routing","user":{"login":"JockLawrie","id":11449078,"avatar_url":"https://avatars.githubusercontent.com/u/11449078?v=3","gravatar_id":"","url":"https://api.github.com/users/JockLawrie","html_url":"https://github.com/JockLawrie","followers_url":"https://api.github.com/users/JockLawrie/followers","following_url":"https://api.github.com/users/JockLawrie/following{/other_user}","gists_url":"https://api.github.com/users/JockLawrie/gists{/gist_id}","starred_url":"https://api.github.com/users/JockLawrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JockLawrie/subscriptions","organizations_url":"https://api.github.com/users/JockLawrie/orgs","repos_url":"https://api.github.com/users/JockLawrie/repos","events_url":"https://api.github.com/users/JockLawrie/events{/privacy}","received_events_url":"https://api.github.com/users/JockLawrie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-14T03:25:03Z","updated_at":"2015-09-14T23:33:18Z","closed_at":null,"body":"\r\n\r\nHi Eric,\r\n\r\nI copied your message (below) into a new issue that focuses on routing - hope you don't mind.\r\n\r\nGlad the [tutorial](https://bitbucket.org/jocklawrie/skeleton-webapp.jl/src/fae46c05fbaf7921a86616bcaf565ebf5a241239/docs/outline.md?fileviewer=file-view-default) appeals. First of all, I'm no web dev guru. I'm just learning, so please take what I'm saying with a grain of salt and compare to other opinions.\r\n\r\nThat said, while I haven't needed routing so far, my approach to routing in Julia web apps would be to use existing packages to get the desired functionality, then if significant boilerplate code is required create a package that contains this boilerplate. So I'd probably do something like this:\r\n\r\n1) Use `URIParser.jl` to extract the different parts of the URL (which is a type of URI) into separate fields of a URI object.\r\n2) The most relevant parts will probably be the `path` and `query` fields.\r\n    a) Compare the path to a regex...see the apps in the tutorial for examples\r\n    b) Extract any path parameters if they exist\r\n    c) Parse the query into a dict using `parsequerystring()` in `HttpCommon.jl`\r\n\r\nThe code would look something like this:\r\n\r\n```\r\nfunction app(req::Request)\r\n    res = Response()    # Init response\r\n\r\n    # Extract information from request\r\n    uri = URI(req.resource)\r\n    path_params = extract_path_params(uri.path)\r\n    q = parsequerystring(uri.query)\r\n\r\n    # Dispatch to handler\r\n    if condition1\r\n        handler1        # Modifies response\r\n    elseif condition2\r\n        handler2        # Modifies response\r\n    ...\r\n    end\r\n    res\r\nend\r\n```\r\n\r\nThe conditions in the branching logic can be functions of the uri, parameters and/or query as appropriate.\r\n\r\nThis approach enables one to get into the mechanics of routing and understand what's happening. You may prefer a ready-made solution such as `Mux.jl` from @one-more-minute.\r\n\r\nHope this helps,\r\nJock\r\n\r\n----------------\r\nFrom @EricForgy\r\n\r\nHi JockLawrie,\r\n\r\nI think I am the exact target audience for your tutorial and remember seeing an earlier version of it. I will definitely work through it. I have been meaning to ask a general question though and your third bullet point above pushes me to ask it (before reading the tutorial - dangerous!).\r\n\r\nI have 20+ years working with Matlab including some web-based work (taking advantage of the fact you can embed Java in m-files) and now I am hoping to build Julia web apps. I was a little sad to see Morsel.jl abandoned, but really, the feature I used from Morsel was routing and I liked the way it worked. I plan to give Mux.jl a try, but was wondering if I could ask about \"best practices\" for routing. Is just HttpCommon and HttpServer sufficient?\r\n\r\nI need enterprise quality technology suitable for large financial institutions.\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/comments/140233140","html_url":"https://github.com/JuliaWeb/Roadmap/issues/9#issuecomment-140233140","issue_url":"https://api.github.com/repos/JuliaWeb/Roadmap/issues/9","id":140233140,"user":{"login":"JockLawrie","id":11449078,"avatar_url":"https://avatars.githubusercontent.com/u/11449078?v=3","gravatar_id":"","url":"https://api.github.com/users/JockLawrie","html_url":"https://github.com/JockLawrie","followers_url":"https://api.github.com/users/JockLawrie/followers","following_url":"https://api.github.com/users/JockLawrie/following{/other_user}","gists_url":"https://api.github.com/users/JockLawrie/gists{/gist_id}","starred_url":"https://api.github.com/users/JockLawrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JockLawrie/subscriptions","organizations_url":"https://api.github.com/users/JockLawrie/orgs","repos_url":"https://api.github.com/users/JockLawrie/repos","events_url":"https://api.github.com/users/JockLawrie/events{/privacy}","received_events_url":"https://api.github.com/users/JockLawrie/received_events","type":"User","site_admin":false},"created_at":"2015-09-14T23:33:18Z","updated_at":"2015-09-14T23:33:18Z","body":"@hayd sounds great, looking forward to seeing what you come up with.\r\n\r\nI'm coming from a learning perspective. One approach a beginner can take is learn a framework, make the right incantations and get something up and running. A more thorough approach is to gradually learn all the basic moving parts, their purpose and limitations, and how they fit together. \r\n\r\nRegarding routing, the relevant questions for a beginner are:\r\n1) At what point does an application become sufficiently complex to warrant additional packages such as Mux?\r\n2) Even if not strictly required, can the additional packages bring other benefits such as simpler code, shorter development time, better performance, etc?\r\n\r\nAnswering either of these still requires an understanding of the basics as a basis for comparison. I hope the [tutorial](https://bitbucket.org/jocklawrie/skeleton-webapp.jl/overview) will eventually provide this understanding (though the docs are admittedly a little thin at this stage).\r\n\r\nFor example, Example 3 of the tutorial shows around a dozen paths (including static files) handled by a 3-clause if statement, a regex and a hash table. That is, we don't need one clause per path and there is scope to increase the number of paths without increasing the size of the if statement. So this use case is simple enough to stick with the basic packages. A user can leave it at that or introduce Mux into the stack and see if that helps readability, performance, etc. I think this provides a solid learning experience.\r\n\r\nThoughts?"}}