JuliaWeb / JuliaWeb/Roadmap

Routing

Open
#9 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
7
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Hi Eric,

I copied your message (below) into a new issue that focuses on routing - hope you don't mind.

Glad 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.

That 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:

1) Use `URIParser.jl` to extract the different parts of the URL (which is a type of URI) into separate fields of a URI object.
2) The most relevant parts will probably be the `path` and `query` fields.
a) Compare the path to a regex...see the apps in the tutorial for examples
b) Extract any path parameters if they exist
c) Parse the query into a dict using `parsequerystring()` in `HttpCommon.jl`

The code would look something like this:

```
function app(req::Request)
res = Response() # Init response

# Extract information from request
uri = URI(req.resource)
path_params = extract_path_params(uri.path)
q = parsequerystring(uri.query)

# Dispatch to handler
if condition1
handler1 # Modifies response
elseif condition2
handler2 # Modifies response
...
end
res
end
```

The conditions in the branching logic can be functions of the uri, parameters and/or query as appropriate.

This 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.

Hope this helps,
Jock

---

From @EricForgy

Hi JockLawrie,

I 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!).

I 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?

I need enterprise quality technology suitable for large financial institutions.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.