To create a Genie based app

  1. Start Julia
  2. In the shell environment cd to the parent folder where you want your project to be
  3. Exit the shell environment
  4. Type the following:
    using Genie, Genie.Generator
    Genie.Generator.newapp("MyGenieApp")

The web server is automatically started. A browser pointed at http://127.0.0.1:8000 displays the default welcome page.

Continuing the development

Type: Genie.Generator.newcontroller("Books")

A folder is created under app resources. Put code in the BooksController.jl file. The code in the tutorial encodes the html, which is a multiline string including double quote marks inside it, using just one double quote mark at the start and end... It needs triple quotes. If html is to be returned then the module needs the following:


# app/resources/books/BooksController.jl
module BooksController
using Genie.Renderer.Html

struct Book
  title::String
  author::String
end

const BillGatesBooks = Book[
  Book("The Best We Could Do", "Thi Bui"),
  Book("Evicted: Poverty and Profit in the American City", "Matthew Desmond"),
  Book("Believe Me: A Memoir of Love, Death, and Jazz Chickens", "Eddie Izzard"),
  Book("The Sympathizer", "Viet Thanh Nguyen"),
  Book("Energy and Civilization, A History", "Vaclav Smil")
]

function billgatesbooks()
   msg = """
<h1>Bill Gates' list of recommended books</h1>
<ul>
  $(["<li>$(book.title) by $(book.author)</li>" for book in BillGatesBooks]...)
</ul>
"""
  html(msg)
end

end

Test out in the repl:


using BooksController
BooksController.billgatesbooks()

We see the text output of the method.

Put a route, using 'bgbooks' as the route, in routes.jl. Using the browser and adding /bgbooks to the url should list Bil Gates' favourite books.

A valuable lesson happened when the code had errors. The error message is to the effect that the module is not included in the project. What it really means is that it didn't compile so it isn't there at all. Fixing the code meant that the uses of the function in the app suddenly start working!

Restarting a project

  1. Open up a terminal
  2. cd to the project folder
  3. type ./bin/repl
  4. Ignore this message: "Package MyGenieApp does not have SearchLight in its dependencies"
  5. Start the web service: up()
  6. In the browser go to: http://127.0.0.1:8000/

The web application should start at its welcome page.

To fix the SearchLight problem, when the app is loaded as above, use ] to enter package mode. Then type add SearchLight. It will be added to the project and recompilations where necessary will happen. Press the backspace key to exit this mode.