# Request for example: "Hello world \[name\]" as a web app, aka how to pass to Julia the inputs of a web form and retrieve the output as a html response

**URL:** https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803
**Category:** Web Stack
**Created:** [October 22, 2020, 7:38am UTC](https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803 "2020-10-22T07:38:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 22, 2020, 7:38am UTC](https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803/1 "2020-10-22T07:38:45Z")

</div>

I need to expose a Julia function as a web app, where users fill a simple (static?) html form with a couple of input fields and a file input (for a csv file) and the “web app” responds with a string to be formatted as a html page to be shown to the user.  
Which is the simplest way to achieve that ? I already have apache running on the server, does some sort of mod\_julia exists? Or like in the perl/cgi era ? Or one need to run a julia-specific server (this would be my least desired method, as it implies I need to have the julia server running all the time, while this app is gonna to be used rarely) ? Does a complete “Hello world [name]” example exists from which to expand ?

I don’t care if the user has to wait a few seconds for the script to JIT compile…

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 22, 2020, 9:13am UTC](https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803/2 "2020-10-22T09:13:49Z")

</div>

I am learning how to do it with [Genie](https://genieframework.github.io/Genie.jl/dev/tutorials/8--Handling_File_Uploads.html)… do you think it would be the best approach for my user case or it is like using a nuclear bomb to remove a stump ?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 22, 2020, 12:39pm UTC](https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803/3 "2020-10-22T12:39:19Z")

</div>

With Genie I am now doing…

```julia
using Genie, Genie.Router, Genie.Renderer.Html, Genie.Requests, CSV, DataFrames
form = """
<form action="/" method="POST" enctype="multipart/form-data">
  <label for="dataFile">Data file (CSV): </label><input type="file" name="dataFile" />
  <br/><input type="submit" value="Find environmental efficiency scores" />
</form>
"""
route("/") do
  html(form)
end

route("/", method = POST) do
  if infilespayload(:dataFile)
    write(filespayload(:dataFile))
    csvcontent = CSV.read(filename(filespayload(:dataFile)),DataFrame; delim=';',copycols=true)
   # [... work on the dataframe...]
  else
    "No data file uploaded"
  end
end

up()

```

Is there a way to avoid _writing_ the file ?

---

<div class="post-metadata">

### Author: ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)
#### Post date: [March 8, 2021, 1:51am UTC](https://discourse.julialang.org/t/request-for-example-hello-world-name-as-a-web-app-aka-how-to-pass-to-julia-the-inputs-of-a-web-form-and-retrieve-the-output-as-a-html-response/48803/4 "2021-03-08T01:51:39Z")

</div>

Never used Genie, but by reading the doc  
`filespayload(:dataFile)` should return a `Input.HttpFile`

And by examining the definition

```julia
mutable struct HttpFile
  name::String
  mime::String
  data::Array{UInt8}
end

```

it has a `data` field, you could probably just stuff that array into `CSV.File`
