### Create and Run a Basic Genie App (Julia) Source: https://learn.genieframework.com/docs/reference/reactive-UI This snippet demonstrates the essential steps to create a new Genie application, including project setup, package installation, defining a simple UI with reactive elements, and running the application. ```julia mkdir MyGenieApp cd MyGenieApp julia --project pkg> add GenieFramework module App using GenieFramework @genietools @app begin @in name = "Genie" end function ui() [ h1("My First Genie App") input("Enter your name", :name) p("Hello {{message}}!") ] end @page("/", ui) end using GenieFramework Genie.loadapp() up() ``` -------------------------------- ### Genie Framework Initializer Example: SearchLight ORM Setup (Julia) Source: https://learn.genieframework.com/framework/genie.jl/docs/initializers This code snippet demonstrates a typical initializer file for setting up the SearchLight ORM in a Genie application. It loads SearchLight configuration, sets up the database adapter, establishes a connection, and loads resources if database configuration is present. This initializer relies on the SearchLight package and its QueryBuilder module. ```julia using SearchLight, SearchLight.QueryBuilder SearchLight.Configuration.load() if SearchLight.config.db_config_settings["adapter"] !== nothing SearchLight.Database.setup_adapter() SearchLight.Database.connect() SearchLight.load_resources() end ``` -------------------------------- ### Run Genie Interactively: Basic Routing and Server Start Source: https://learn.genieframework.com/framework/genie.jl/docs/introduction Demonstrates how to define a simple route and start the Genie web server interactively within a Julia REPL or notebook. The `route` function maps a URL to a handler function, and `up()` starts the server. ```julia using Genie route("/hello") do "Hello World" end up() ``` -------------------------------- ### Develop a Simple Genie Micro-service Script Source: https://learn.genieframework.com/framework/genie.jl/docs/introduction This example illustrates creating a basic Genie web service script (`geniews.jl`). It defines routes for HTML, JSON, and plain text responses using Genie's rendering utilities and starts the server synchronously. ```julia using Genie, Genie.Renderer, Genie.Renderer.Html, Genie.Renderer.Json route("/hello.html") do html("Hello World") end route("/hello.json") do json("Hello World") end route("/hello.txt") do respond("Hello World", :text) end up(8001, async = false) ``` -------------------------------- ### GET /api/hello/:name Source: https://learn.genieframework.com/framework/genie.jl/guides/creating-an-api An example endpoint that greets a user by name. The name is passed as a path parameter. ```APIDOC ## GET /api/hello/:name ### Description This endpoint greets a user by name. The name is provided as a path parameter in the URL. ### Method GET ### Endpoint /api/hello/:name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the user to greet. ### Request Example ``` GET /api/hello/John ``` ### Response #### Success Response (200) - **string** - A greeting message. #### Response Example ```json "Hello John" ``` ``` -------------------------------- ### Import and Install Genie Plugin (Julia) Source: https://learn.genieframework.com/framework/genie.jl/docs/plugins These commands show how to bring a Genie plugin into scope using the `using` keyword and then install it into the current Genie application. The installation is a one-time operation that copies plugin files into the app. ```julia julia> using HelloPlugin julia> HelloPlugin.install(@__DIR__) ``` -------------------------------- ### GET /api/hello/:name Source: https://learn.genieframework.com/tutorials/multipage-app An example endpoint that greets a user by name. It demonstrates defining a route with a path parameter and a simple handler function. ```APIDOC ## GET /api/hello/:name ### Description Greets a user by name using a path parameter. ### Method GET ### Endpoint /api/hello/:name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the user to greet. ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **string** - A greeting message. #### Response Example ``` "Hello World" ``` ``` -------------------------------- ### Start Julia and Activate Project Source: https://learn.genieframework.com/docs/api/server/configuration This command starts the Julia REPL within your project directory, ensuring that the project's dependencies are managed correctly. ```bash julia --project ``` -------------------------------- ### Start Genie Web Server Source: https://learn.genieframework.com/framework/genie.jl/guides/working-with-genie-projects Starts the Genie web server, returning the user to the interactive Julia REPL. This is the initial step to run a Genie application. ```julia up() ``` -------------------------------- ### Enable and Start Supervisor Service Source: https://learn.genieframework.com/docs/guides/deploying-genie-apps Enable the supervisor service to start automatically on system boot and start the service immediately. This is part of troubleshooting startup issues. ```bash sudo systemctl enable supervisor.service sudo systemctl start supervisor.service ``` -------------------------------- ### Import Julia Code with StatsBase and GenieFramework Source: https://learn.genieframework.com/geniebuilder/docs/quick-start This snippet shows how to import necessary Julia packages like StatsBase and GenieFramework, define a statistics function, and set up the basic app structure using @app and @page macros. It assumes the StatsBase package is installed. ```julia module App using StatsBase: mean, std, var using GenieFramework, PlotlyBase @genietools function statistics(x) mean(x), std(x), var(x) end @app begin # reactive code goes here end @page("/", "app.jl.html") end ``` -------------------------------- ### Start Genie App Server (Julia) Source: https://learn.genieframework.com/framework/genie.jl/docs/plugins This command starts the Genie web server for the application. It is typically run after navigating to the app's directory and starting the Julia REPL within it. ```julia julia> up() ``` -------------------------------- ### Start Genie Web Server Source: https://learn.genieframework.com/tutorials/mvc-books-app Starts the Genie web server, returning control to the Julia REPL. This is the initial step to run a Genie application. ```julia julia> up() ``` -------------------------------- ### Install Docker on EC2 Instance Source: https://learn.genieframework.com/framework/guides/deployments/deploying-to-aws Commands to install Docker on an Amazon Linux 2 EC2 instance. This includes updating the system, installing the docker package, adding the ec2-user to the docker group, enabling and starting the Docker service. ```bash sudo yum update sudo yum install docker -y sudo usermod -a -G docker ec2-user id ec2-user newgrp docker sudo systemctl enable docker.service sudo systemctl start docker.service ``` -------------------------------- ### Starting Genie Web Server Source: https://learn.genieframework.com/framework/genie.jl/api/server The `up` function starts the Genie web server. It accepts arguments for the port, host, and WebSocket port, and can be configured to run asynchronously. It returns a ServersCollection object containing the running server tasks. ```julia up(port::Int = Genie.config.server_port, host::String = Genie.config.server_host; ws_port::Int = Genie.config.websockets_port, async::Bool = ! Genie.config.run_as_server) :: ServersCollection ``` -------------------------------- ### Install Git and Clone Repository on EC2 Source: https://learn.genieframework.com/framework/guides/deployments/deploying-to-aws Commands to install Git on an EC2 instance if it's not already present, and then clone a Git repository containing the Genie application and its Dockerfile. Replace '' with the actual repository URL. ```bash sudo yum git install -y # And clone your git repo git clone cd ``` -------------------------------- ### GeniePlugins.install Method Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieplugins/genieplugins The `install` method provides a utility for users to install a Genie plugin from a specified path to a destination. ```APIDOC ## GeniePlugins.install ### Description Utility to allow users to install a plugin. ### Method `install(path::String, dest::String; force = false)` ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Method Parameters - **path** (String) - Required - The source path of the plugin to install. - **dest** (String) - Required - The destination path where the plugin will be installed. - **force** (Boolean) - Optional - If true, overwrites existing files. Defaults to `false`. ### Request Example N/A ### Response N/A (Performs file operations) ``` -------------------------------- ### Clone and Install Genie App Source: https://learn.genieframework.com/docs/guides/deploying-genie-apps Clone the Genie application's source code from a Git repository and navigate into the project directory. This prepares the environment for installing dependencies. ```bash git clone github.com/user/MyGenieApp cd MyGenieAp ``` -------------------------------- ### Basic Swagger UI Setup with Genie.jl Source: https://learn.genieframework.com/framework/genie.jl/plugins/swagui Demonstrates a simple setup for serving Swagger UI documentation using Genie.jl. It loads a swagger.json file and defines a route '/docs' to render the UI. ```julia using Genie, Genie.Router using JSON using SwagUI # use a swagger json from the local machine swagger_document = JSON.parsefile("./swagger.json") route("/docs") do render_swagger(swagger_document) end ``` -------------------------------- ### Install NGINX (Shell) Source: https://learn.genieframework.com/framework/guides/deployments/nginx-reverse-proxy Installs the NGINX web server on a Debian-based Linux system using apt-get. It updates the package list, installs NGINX, and then starts the NGINX service, enabling it to start automatically on boot. ```shell sudo apt-get update sudo apt-get install nginx sudo systemctl start nginx sudo systemctl enable nginx ``` -------------------------------- ### POST /api/v1/apps/{app_id}/start Source: https://learn.genieframework.com/framework/genie.jl/plugins/geniebuilder Starts a registered Genie application identified by its `app_id`. ```APIDOC ## POST /api/v1/apps/{app_id}/start ### Description Starts a Genie application that has been previously registered with GenieBuilder. The application must be in a state where it can be started (e.g., not already running). ### Method POST ### Endpoint /api/v1/apps/{app_id}/start ### Parameters #### Path Parameters - **app_id** (string) - Required - The unique identifier of the application to start. ### Request Example ``` POST /api/v1/apps/1/start ``` ### Response #### Success Response (200) - Typically returns a confirmation message or the updated status of the application. #### Response Example (Response details may vary based on implementation, often a success status or updated app object) ```json { "message": "App with ID 1 started successfully." } ``` ``` -------------------------------- ### Install GenieAuthorisation Plugin Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieauthorisation Adds the GenieAuthorisation.jl package to a Genie.jl application's environment and installs its files. This requires the application to be running within a Genie.jl MVC setup. ```julia (MyGenieApp) pkg> add GenieAuthorisation julia> using GenieAuthorisation julia> GenieAuthorisation.install(@__DIR__) ``` -------------------------------- ### Setup Database Connection with Genie Source: https://learn.genieframework.com/framework/genie.jl/guides/working-with-genie-projects This command initializes the database support for Genie by creating a `db/` folder and a `db/connection.yml` file. The `connection.yml` file configures how SearchLight connects to the database, specifying the environment, adapter, and database file path. It assumes the database file will be created automatically if it doesn't exist. ```julia julia> Genie.Generator.db_support() ``` ```yaml env: ENV["GENIE_ENV"] dev: adapter: SQLite database: db/books.sqlite config: ``` -------------------------------- ### Get Genie Package Information Source: https://learn.genieframework.com/framework/genie.jl/api/configuration Retrieves information about an installed Genie package specified by its name. This function is useful for introspection and dependency management. ```julia Genie.Configuration.pkginfo("Genie") ``` -------------------------------- ### Genie.Server.up - Function Source: https://learn.genieframework.com/framework/genie.jl/api/server Starts the web server, optionally configuring ports, host, and WebSocket port. ```APIDOC ## POST /server/up ### Description Starts the web server. Allows configuration of the port, host, and WebSocket port. ### Method POST ### Endpoint /server/up ### Parameters #### Request Body - **port** (Integer) - Optional - The port used by the web server. Defaults to `Genie.config.server_port`. - **host** (String) - Optional - The host used by the web server. Defaults to `Genie.config.server_host`. - **ws_port** (Integer) - Optional - The port used by the WebSocket server. Defaults to `Genie.config.websockets_port`. - **async** (Boolean) - Optional - Run the web server task asynchronously. Defaults to `!Genie.config.run_as_server`. ### Request Example ```json { "port": 8000, "host": "127.0.0.1", "ws_port": 8001, "async": false } ``` ### Response #### Success Response (200) - **servers** (ServersCollection) - A collection containing references to the started web and WebSocket servers. #### Response Example ```json { "servers": { "webserver": "", "websockets": "" } } ``` ``` -------------------------------- ### Create New Genie App Source: https://learn.genieframework.com/framework/genie.jl/guides/working-with-genie-projects Generates a new Genie web application with a predefined structure. This command initializes a new directory, installs dependencies, sets up a Julia project, and starts the web server. ```julia julia> Genie.Generator.newapp("MyGenieApp") ``` -------------------------------- ### Get First Element of Iterable Collection (Julia) Source: https://learn.genieframework.com/framework/searchlight.jl/api/querybuilder Retrieves the first element from an iterable collection. For `AbstractRange`, it returns the start point, even if the range is empty. Related functions include `only`, `firstindex`, and `last`. ```julia julia> first(2:2:10) 2 julia> first([1; 2; 3; 4]) 1 ``` -------------------------------- ### Load and Connect to Database with SearchLight Source: https://learn.genieframework.com/framework/genie.jl/guides/working-with-genie-projects These commands load the SearchLight configuration and establish a connection to the database. `SearchLight.Configuration.load()` reads the `db/connection.yml` file, and `SearchLight.connect()` uses this configuration to create a database handle. The `SearchLightSQLite.CONNECTIONS` collection can be used to access the active connection. ```julia julia> using SearchLight julia> SearchLight.Configuration.load() Dict{String,Any} with 4 entries: "options" => Dict{String,String}() "config" => nothing "database" => "db/books.sqlite" "adapter" => "SQLite" julia> using SearchLightSQLite julia> SearchLight.Configuration.load() |> SearchLight.connect SQLite.DB("db/books.sqlite") julia> SearchLightSQLite.CONNECTIONS 1-element Array{SQLite.DB,1}: SQLite.DB("db/books.sqlite") ``` -------------------------------- ### Generate New Genie MVC App Source: https://learn.genieframework.com/tutorials/mvc-books-app Creates a new Genie MVC application with the specified name. This command sets up the project structure, installs dependencies, and starts the web server. ```julia Genie.Generator.newapp("MyGenieApp") ``` -------------------------------- ### SearchLight.Migration.up Source: https://learn.genieframework.com/framework/searchlight.jl/api/migrations Runs up the migration corresponding to the provided module name. Optionally forces the migration. ```APIDOC ## POST /websites/learn_genieframework/migrations/up ### Description Runs up the migration corresponding to `migration_module_name`. If `force` is `true`, the migration will be executed even if it's already up. ### Method POST ### Endpoint /websites/learn_genieframework/migrations/up ### Parameters #### Query Parameters - **migration_module_name** (String) - Required - The name of the migration module to run up. - **force** (Boolean) - Optional - If `true`, forces the migration execution. ### Response #### Success Response (200) - **String** - A message indicating the migration status. #### Response Example ```json { "message": "Migration 'create_users_table' migrated up successfully." } ``` ``` -------------------------------- ### Configure Dropdown Icon Source: https://learn.genieframework.com/framework/stipple.jl/plugins/stippleui/selects Sets the icon name for the dropdown. Requires the icon library to be installed or uses an 'img:' prefix for image paths. If set to 'none', no icon is rendered but space is reserved. Examples include 'map', 'ion-add', or image URLs. ```genie dropdownicon::String ``` -------------------------------- ### Connect to the Database using SearchLight Source: https://learn.genieframework.com/framework/searchlight.jl/docs/accessing This command establishes a connection to the database using the loaded configuration. It requires both `SearchLight` and the specific database adapter (e.g., `SearchLightSQLite`) to be loaded. ```julia julia> using SearchLightSQLite julia> SearchLight.Configuration.load() |> SearchLight.connect ``` -------------------------------- ### Initialize SearchLight Migrations Source: https://learn.genieframework.com/tutorials/mvc-movies-app Initializes the database table required by SearchLight's migration system. This command should be run after defining the migration files. ```julia julia> SearchLight.Migration.init() ``` -------------------------------- ### Julia Range Functionality Source: https://learn.genieframework.com/framework/stipple.jl/docs/component-gallery Provides examples of the built-in Julia `range` function for creating sequences of numbers. It covers various ways to specify the range using start, stop, step, and length arguments, and explains the different range types returned (UnitRange, OneTo, AbstractRange). ```julia range(1, length = 100) range(1, stop = 100) range(1, step = 5, length = 100) range(1, step = 5, stop = 100) range(1, 10, length = 101) range(1, 100, step = 5) range(stop = 10, length = 5) range(stop = 10, step = 1, length = 5) range(start = 1, step = 1, stop = 10) range(; length = 10) range(; stop = 6) range(; stop = 6.5) range(1, 3.5, step = 2) ``` -------------------------------- ### Genie Framework App Structure with Reactive Variables and Handlers Source: https://learn.genieframework.com/geniebuilder/docs/quick-start This Julia code defines the main structure of a Genie Framework application. It includes reactive input ('@in') and output ('@out') variables, a custom 'statistics' function, and an @onchange handler to update statistics when 'N' changes. It also sets up the main page route. ```julia module App using StatsBase: mean, std, var using GenieFramework, PlotlyBase @genietools function statistics(x) mean(x), std(x), var(x) end @app begin @in N = 0 @out x = randn(10) @out m::Float32 = 0.0 @out s::Float32 = 0.0 @out v::Float32 = 0.0 @onchange N begin x = randn(N) m, s, v = statistics(x) end end @page("/", "app.jl.html") end ``` -------------------------------- ### Install Genie Plugin (Julia) Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieplugins/genieplugins Utility to allow users to install a plugin. This method requires the source path of the plugin and the destination path for installation. It includes an optional 'force' parameter to overwrite existing installations. ```Julia install(path::String, dest::String; force = false) ``` -------------------------------- ### Genie.up Source: https://learn.genieframework.com/framework/genie.jl/api/genie Starts the web server, with options for port, host, and asynchronous execution. ```APIDOC ## Genie.up ### Description Starts the web server. This is an alias for `Server.up`. It allows configuration of the port, host, and WebSocket port, as well as whether to run the server asynchronously. ### Method `up(port::Int = Genie.config.server_port, host::String = Genie.config.server_host; ws_port::Int = Genie.config.websockets_port, async::Bool = ! Genie.config.run_as_server)` ### Endpoint N/A (Function call) ### Parameters - `port` (Int): Optional. The port used by the web server. Defaults to `Genie.config.server_port`. - `host` (String): Optional. The host used by the web server. Defaults to `Genie.config.server_host`. - `ws_port` (Int): Optional. The port used by the Web Sockets server. Defaults to `Genie.config.websockets_port`. - `async` (Bool): Optional. Run the web server task asynchronously. Defaults to `! Genie.config.run_as_server`. ### Request Example ```julia using Genie # Start server on default port and host, synchronously Genie.up(async = false) # Start server on a specific port and host, asynchronously Genie.up(8000, "127.0.0.1", async = true) ``` ### Response #### Success Response - `Nothing`: This function does not return a value upon successful execution, but it starts the server and prints status messages. #### Response Example ``` [ Info: Ready! Web Server starting at http://127.0.0.1:8000 ``` ``` -------------------------------- ### Load Database Configuration Source: https://learn.genieframework.com/tutorials/mvc-movies-app Manually loads the database configuration by including the SearchLight initializer file. This step is necessary after modifying the `db/connection.yml`. ```julia julia> include(joinpath("config", "initializers", "searchlight.jl")) ``` -------------------------------- ### Declare Reactive Variables for App Logic Source: https://learn.genieframework.com/geniebuilder/docs/quick-start This code block defines reactive variables within the @app macro. It includes input variables like 'N' and output variables like 'x', 'm', 's', and 'v' to manage the app's state and data flow between the frontend and backend. Initialization of reactive variables with other reactive variables is not supported. ```julia @app begin @in N = 0 @out x = randn(10) @out m::Float32 = 0.0 @out s::Float32 = 0.0 @out v::Float32 = 0.0 end ``` -------------------------------- ### StippleUI.Menus.menu Basic Usage Example Source: https://learn.genieframework.com/framework/stipple.jl/plugins/stippleui/menus Demonstrates a basic example of how to use the StippleUI.Menus.menu component with a button in a Genie Framework application. This example shows a simple menu with a 'Hello' message. ```julia btn("Basic Menu", color="primary", [StippleUI.menu(nothing, [p("Hello")])]) ``` -------------------------------- ### Initialize Database Migrations with SearchLight Source: https://learn.genieframework.com/framework/genie.jl/guides/working-with-genie-projects This command initializes the database schema for managing migrations by creating a `schema_migrations` table. This table is used by SearchLight to keep track of which migration scripts have been applied. The `SearchLight.query()` function can be used to execute arbitrary SQL queries against the database, for example, to verify the existence of the created table. ```julia julia> SearchLight.Migrations.init() [ Info: Created table schema_migrations julia> SearchLight.query("SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%' ``` -------------------------------- ### Genie.Server.setup_http_listener - Function Source: https://learn.genieframework.com/framework/genie.jl/api/server Configures the handler for HTTP requests and manages errors. ```APIDOC ## POST /listener/http/setup ### Description Configures the handler for the HTTP Request and handles errors. ### Method POST ### Endpoint /listener/http/setup ### Parameters #### Request Body - **req** (HTTP.Request) - Required - The incoming HTTP request object. - **res** (HTTP.Response) - Optional - The HTTP response object to be configured. Defaults to an empty response. ### Request Example ```json { "req": { ... }, "res": { ... } } ``` ### Response #### Success Response (200) - **res** (HTTP.Response) - The configured HTTP response object. #### Response Example ```json { "res": { ... } } ``` ``` -------------------------------- ### HTML Structure for Genie Framework App with UI Components Source: https://learn.genieframework.com/geniebuilder/docs/quick-start This HTML code defines the user interface for a Genie Framework application. It includes a header, a slider bound to the reactive variable 'N', and display areas for statistical outputs (mean, standard deviation, variance) bound to 'm', 's', and 'v' respectively. It also includes a placeholder for a Plotly chart. ```html

Normal distribution statistics

Number of samples

Mean

St. dev.

Variance

``` -------------------------------- ### Define Reactive Handler with @onchange in Genie Framework Source: https://learn.genieframework.com/geniebuilder/docs/quick-start This code snippet demonstrates how to define a reactive handler using the @onchange macro within a Genie Framework application. The handler watches the reactive variable 'N' and executes a block of code to update statistics when 'N' changes. It relies on the 'randn' function for random number generation and a custom 'statistics' function. ```julia @app begin . . . @onchange N begin x_rand = randn(N) m, s, v = statistics(x_rand) end end end ``` -------------------------------- ### Generate Database Support Files with Genie Source: https://learn.genieframework.com/framework/searchlight.jl/docs/accessing This command utilizes Genie's generator to set up the necessary database support files, including the `db/connection.yml` configuration file. It simplifies the initial setup for database connections. ```julia julia> Genie.Generator.db_support() ``` -------------------------------- ### Install GenieAuthentication Plugin in Genie.jl App Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieauthentication Steps to install the GenieAuthentication.jl plugin into an existing Genie.jl MVC application. This involves adding the package via the Julia package manager and then running the install function to set up plugin files. ```julia cd /path/to/your/genie_app ./bin/repl (MyGenieApp) pkg> add GenieAuthentication using GenieAuthentication GenieAuthentication.install(@__DIR__) ``` -------------------------------- ### Load SearchLight Database Configuration Source: https://learn.genieframework.com/framework/searchlight.jl/docs/accessing This command loads the database connection configuration defined in `db/connection.yml`. It returns a dictionary containing the database adapter and connection details. ```julia julia> using SearchLight julia> SearchLight.Configuration.load() ``` -------------------------------- ### Genie Framework Imports and Setup (Julia) Source: https://learn.genieframework.com/tutorials/reactive-ui-basics This snippet shows the necessary imports for a Genie Framework application in Julia. It includes the GenieFramework package and utilizes the @genietools macro to configure the development environment. ```julia using GenieFramework @genietools ``` -------------------------------- ### Load and Connect to Database in SearchLight Source: https://learn.genieframework.com/tutorials/mvc-books-app These commands load the SearchLight configuration and establish a connection to the database. The `SearchLight.Configuration.load()` function reads the `connection.yml` file, and `SearchLight.connect()` initiates the actual database connection, returning a database handle. ```julia julia> using SearchLight julia> SearchLight.Configuration.load() Dict{String,Any} with 4 entries: "options" => Dict{String,String}() "config" => nothing "database" => "db/books.sqlite" "adapter" => "SQLite" julia> using SearchLightSQLite julia> SearchLight.Configuration.load() |> SearchLight.connect ``` -------------------------------- ### Enabling and Starting Genie WebSocket Server Source: https://learn.genieframework.com/framework/genie.jl/docs/websockets Configures and starts the Genie web application with WebSocket server support enabled. This involves setting `Genie.config.websockets_server = true`, defining the root route to include client-side WebSocket support, and then starting the server using `up()`. ```julia using Genie, Genie.Router, Genie.Assets Genie.config.websockets_server = true # enable the websockets server route("/") do Assets.channels_support() end up() # start the servers ``` -------------------------------- ### Create a New Genie App Project Source: https://learn.genieframework.com/framework Commands to create a new project folder, navigate into it, and start Julia with the project activated. ```bash mkdir MyGenieApp cd MyGenieApp julia --project ``` -------------------------------- ### Install GenieFramework Package Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieframework This command installs the latest released version of the GenieFramework package using the Julia package manager. ```julia pkg> add GenieFramework ``` -------------------------------- ### Launch and Manage Genie App (Julia REPL) Source: https://learn.genieframework.com/framework/stipple.jl/guides/first-dashboard These commands are used in the Julia REPL to load and run a Genie.jl application. `Genie.loadapp()` loads the application defined in the current directory, and `up()` starts the web server. `down()` is used to stop the server. ```julia using GenieFramework; Genie.loadapp(); up() ``` ```julia down() ``` -------------------------------- ### Install Certbot for NGINX on Ubuntu 20.04 Source: https://learn.genieframework.com/framework/guides/deployments/nginx-reverse-proxy This snippet shows the commands to install Certbot, a tool for automatically enabling HTTPS with Let's Encrypt, on Ubuntu 20.04 using snap packages. It ensures Certbot is installed and accessible via a symlink. ```bash sudo snap install core; sudo snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot ``` -------------------------------- ### Install GenieBuilder.jl Source: https://learn.genieframework.com/framework/genie.jl/plugins/geniebuilder Installs the GenieBuilder.jl package from GitHub. It can be added directly or developed locally. This step is crucial for using GenieBuilder's features. ```julia pkg> add https://github.com/GenieFramework/GenieBuilder.jl#v0.16 ``` ```julia pkg> dev https://github.com/GenieFramework/GenieBuilder.jl#v0.16 ``` -------------------------------- ### Install StippleKeplerGL Package Source: https://learn.genieframework.com/framework/stipple.jl/docs/plugins This command installs the StippleKeplerGL package using the Julia package manager. Ensure you are in the Julia command prompt. ```julia ] add StippleKeplerGL ``` -------------------------------- ### Handling GET Query Parameters Source: https://learn.genieframework.com/framework/genie.jl/docs/payloads Access query parameters from GET requests using the `params()` collection or the `Requests.getpayload()` utility. ```APIDOC ## GET /hi ### Description This endpoint demonstrates how to access query parameters. It expects an optional `name` query parameter and returns a greeting. ### Method GET ### Endpoint /hi ### Parameters #### Query Parameters - **name** (String) - Optional - The name to greet. ### Request Example Accessing `http://127.0.0.1:8000/hi?name=Adrian` ### Response #### Success Response (200) - **Greeting** (String) - A greeting message. #### Response Example ``` "Hello Adrian" ``` ## Using Requests.getpayload() ### Description An alternative method to access query parameters using the `Requests.getpayload()` function, which returns parameters as a `Dict{Symbol,Any}`. ### Method GET ### Endpoint /hi ### Parameters #### Query Parameters - **name** (String) - Optional - The name to greet. ### Request Example Accessing `http://127.0.0.1:8000/hi?name=Adrian` ### Response #### Success Response (200) - **Greeting** (String) - A greeting message. #### Response Example ``` "Hello Adrian" ``` ``` -------------------------------- ### Create and Navigate Project Directory Source: https://learn.genieframework.com/docs/api/server/configuration This snippet demonstrates how to create a new directory for your Genie project and then navigate into it using standard terminal commands. ```bash mkdir MyGenieApp cd MyGenieApp ``` -------------------------------- ### Create SQLQuery Instance in Julia Source: https://learn.genieframework.com/framework/searchlight.jl/api/modeltypes Returns a new instance of SQLQuery, allowing configuration of columns, WHERE conditions, limit, offset, and order. This example demonstrates setting WHERE conditions, offset, limit, and order. ```julia SQLQuery(where = [SQLWhereExpression("id BETWEEN ? AND ?", [10, 20])], offset = 5, limit = 5, order = :title) ``` -------------------------------- ### Extract GET Parameters from URI Source: https://learn.genieframework.com/framework/genie.jl/api/router Extracts query variables from a URI and adds them to the execution `params` `Dict`. This function is used for handling GET requests. ```julia extract_get_params(uri::URI, params::Params) :: Bool ``` -------------------------------- ### Genie.bootstrap Source: https://learn.genieframework.com/framework/genie.jl/api/genie Initializes the Genie framework, returning a TCPServer object or Nothing if not started. ```APIDOC ## Genie.bootstrap ### Description Initializes the Genie framework. Returns a `TCPServer` object if the server is started, otherwise `Nothing`. ### Method `genie()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```julia using Genie genie() ``` ### Response #### Success Response - `Union{Nothing, Sockets.TCPServer}`: A `TCPServer` object if the server is running, or `Nothing`. #### Response Example ```julia # If server is running # TCPServer(...) # If server is not running # nothing ``` ``` -------------------------------- ### Genie.Server.setup_ws_handler - Function Source: https://learn.genieframework.com/framework/genie.jl/api/server Configures the handler for WebSocket requests. ```APIDOC ## POST /listener/ws/setup ### Description Configures the handler for WebSockets requests. ### Method POST ### Endpoint /listener/ws/setup ### Parameters #### Request Body - **stream** (HTTP.Stream) - Required - The HTTP stream for the WebSocket connection. - **ws_client** - Required - The WebSocket client object. ### Request Example ```json { "stream": { ... }, "ws_client": { ... } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the handler setup. #### Response Example ```json { "status": "WebSocket handler setup successfully." } ``` ``` -------------------------------- ### Install Genie App Dependencies Source: https://learn.genieframework.com/docs/guides/deploying-genie-apps Install the application's Julia dependencies using the Pkg manager. This ensures all required packages are available for the application to run. ```julia julia --project ] pkg> instantiate exit() ``` -------------------------------- ### Launch Genie App (Julia REPL) Source: https://learn.genieframework.com/framework/stipple.jl/guides Provides the Julia REPL commands to load and run a Genie.jl application. It starts a web server on port 8000, accessible at `https://localhost:8000`, and includes the command to stop the server. ```julia using GenieFramework; Genie.loadapp(); up() ``` -------------------------------- ### Set Up User Table Migration in Genie.jl Source: https://learn.genieframework.com/framework/genie.jl/plugins/genieauthentication Instructions for setting up the database table required by GenieAuthentication.jl to store user accounts. This involves running a provided migration file using SearchLight.jl. ```julia using SearchLight SearchLight.Migration.up("CreateTableUsers") ``` -------------------------------- ### Setup Resource Path for Persistence Source: https://learn.genieframework.com/framework/searchlight.jl/api/generator Computes and creates the necessary directory structure for persisting a new resource. It requires the resource name as a string. ```julia SearchLight.Generator.setup_resource_path(resource_name::String) :: String ``` -------------------------------- ### Toggle Component Example Source: https://learn.genieframework.com/framework/stipple.jl/docs/component-gallery Demonstrates the usage of the Toggle component for boolean inputs. It includes a model definition and example view configurations for different color selections. ```julia @vars ToggleModel begin value::R{Bool} = false selection::R{Vector{String}} = ["yellow", "red"] end ``` ```julia toggle("Blue", color = "blue", :selection, val = "blue") toggle("Yellow", color = "yellow", :selection, val = "yellow") toggle("Green", color = "green", :selection, val = "green") toggle("Red", color = "red", :selection, val = "red") ``` -------------------------------- ### Install Genie Framework Packages Source: https://learn.genieframework.com/tutorials/iris-clustering-dashboard Installs necessary Julia packages for the project, including RDatasets, DataFrames, Clustering, and GenieFramework. This is a prerequisite for running the tutorial code. ```julia add RDatasets DataFrames Clustering GenieFramework ``` -------------------------------- ### Generate and Serve API Documentation Page Source: https://learn.genieframework.com/tutorials/multipage-app Configures and builds an OpenAPI documentation page for the API. It sets up API information (title, version), generates the Swagger UI HTML, and serves it at the '/api' route without a default layout. ```julia info = Dict{String,Any}() info["title"] = "Boston housing MEDV prediction" info["version"] = "1.0.5" openApi = OpenAPI("3.0", info) swagger_document = build(openApi) ui() = render_swagger(swagger_document) #add route without default layout @page("/api", ui, nothing) ``` -------------------------------- ### Initialize Genie App Entry Point (Julia) Source: https://learn.genieframework.com/tutorials/working-with-forms The `app.jl` file serves as the entry point for the Genie Framework application. It uses `using GenieFramework` to import necessary components and `using Main.StatisticAnalysis` to access the custom module. The `@genietools` macro enables development features like logging and hot code reloading. ```julia module App using GenieFramework using Main.StatisticAnalysis @genietools end ``` -------------------------------- ### Setup Binaries for Windows in Genie Source: https://learn.genieframework.com/framework/genie.jl/api/generator Creates the `bin/server` and `bin/repl` executable files for Windows systems within a Genie project. Defaults to the current directory if no path is specified. ```julia setup_windows_bin_files(path::String = ".") :: Nothing ``` -------------------------------- ### Start a Genie App Managed by GenieBuilder.jl Source: https://learn.genieframework.com/framework/genie.jl/plugins/geniebuilder Starts a specific Genie application that has been registered with GenieBuilder. The function takes an instance of GenieBuilder.Application as input. This is a prerequisite for editing the app with the no-code editor. ```julia julia> GenieBuilder.start(app::Application) ``` -------------------------------- ### Interact with Movie Data using SearchLight Source: https://learn.genieframework.com/tutorials/mvc-movies-app Demonstrates how to create, check persistence, save, count, and retrieve all movie data using the Movie model and SearchLight's ORM capabilities. It requires importing the Movies module. ```julia julia> using Movies julia> m = Movie(title = "Test movie", actors = "John Doe, Jane Doe") julia> ispersisted(m) false julia> save(m) true julia> count(Movie) julia> all(Movie) ``` -------------------------------- ### StippleUI.FormInputs.textfield View Example Source: https://learn.genieframework.com/framework/stipple.jl/plugins/stippleui/forminputs Provides an example of how to use the textfield component within a StippleUI view. It demonstrates setting various properties like label, validation rules, and hints. ```julia julia> textfield("What's your name *", :name, name = "name", @if(:warin), :filled, hint = "Name and surname", "lazy-rules", rules = "[val => val && val.length > 0 || 'Please type something']" ) ``` -------------------------------- ### Install Genie App Dependencies Source: https://learn.genieframework.com/framework/genie.jl/api/generator Installs the application's dependencies using Julia's Pkg manager. This function ensures all required packages are available for the Genie app. ```julia Genie.Generator.install_app_dependencies(app_path::String = ".") :: Nothing ``` -------------------------------- ### DataFrame Constructor Examples Source: https://learn.genieframework.com/framework/searchlight.jl/api/querybuilder Provides various examples of constructing DataFrames using different input formats such as Tables.jl tables, pairs, dictionaries, keyword arguments, vectors of vectors, and matrices. ```julia DataFrame((a=[1, 2], b=[3, 4])) # Tables.jl table constructor ``` ```julia DataFrame([(a=1, b=0), (a=2, b=0)]) # Tables.jl table constructor ``` ```julia DataFrame("a" => 1:2, "b" => 0) # Pair constructor ``` ```julia DataFrame([:a => 1:2, :b => 0]) # vector of Pairs constructor ``` ```julia DataFrame(Dict(:a => 1:2, :b => 0)) # dictionary constructor ``` ```julia DataFrame(a=1:2, b=0) # keyword argument constructor ``` ```julia DataFrame([[1, 2], [0, 0]], [:a, :b]) # vector of vectors constructor ``` ```julia DataFrame([1 0; 2 0], :auto) # matrix constructor ```