### Full WebSocket Example with Genie Server Source: https://genieframework.github.io/Genie.jl/dev/tutorials/17--Working_with_Web_Sockets Provides a complete example to run a Genie application with WebSocket support enabled. This includes configuring the server, setting up the root route, and starting the application. ```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 ``` -------------------------------- ### Genie App Procfile Example Source: https://genieframework.github.io/Genie.jl/dev/tutorials/90--Deploying_With_Heroku_Buildpacks Example content for a Procfile used in Heroku deployment. This file specifies the command to run when your application starts. It includes the Julia executable and project path, along with the PORT environment variable. ```Procfile web: julia --project src/app.jl $PORT ``` -------------------------------- ### Genie.Server.up Source: https://genieframework.github.io/Genie.jl/dev/API/server Starts the web server. ```APIDOC ## Genie.Server.up ### Description Starts the web server. ### Method `up` ### Parameters #### Keyword Arguments - **port** (Int) - The port used by the web server. Defaults to `Genie.config.server_port`. - **host** (String) - The host used by the web server. Defaults to `Genie.config.server_host`. - **ws_port** (Int) - The port used by the Web Sockets server. Defaults to `Genie.config.websockets_port`. - **async** (Bool) - Run the web server task asynchronously. Defaults to `!Genie.config.run_as_server`. ### Returns `ServersCollection` - A collection containing references to the started web and WebSocket servers. ### Examples ```julia Genie.up(8000, "127.0.0.1", async = false) ``` ``` -------------------------------- ### Start Genie App in REPL (macOS/Linux) Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Executes the `bin/repl` script to load a Genie app in an interactive REPL session on macOS or Linux. After loading, the `up()` function can be called to start the web server. ```shell $ bin/repl julia> up() ``` -------------------------------- ### Install and Manage Nginx Server Source: https://genieframework.github.io/Genie.jl/dev/tutorials/92--Deploying_Genie_Server_Apps_with_Nginx Install Nginx on Ubuntu, start the service, and enable it to run on boot. Nginx will act as a reverse proxy for the Genie application. ```bash sudo apt-get update sudo apt-get install nginx sudo systemctl start nginx sudo systemctl enable nginx ``` -------------------------------- ### Define a basic route and start the web server Source: https://genieframework.github.io/Genie.jl/dev/guides/Interactive_environment This snippet shows how to define a simple route that maps the root URL ('/') to a function returning a string. It also demonstrates how to start the Genie web server. Ensure Genie is imported before use. ```julia using Genie route("/") do "Hi there!" end up() ``` -------------------------------- ### Generate *nix REPL/Server Scripts Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Generates the `bin/repl` and `bin/server` scripts for *nix systems (macOS/Linux). These scripts are used to start interactive REPL sessions or server sessions, respectively. ```julia using Genie Genie.Generator.setup_nix_bin_files() ``` -------------------------------- ### Start Genie Server Source: https://genieframework.github.io/Genie.jl/dev/guides/Genie_Plugins Starts the Genie web server, making the application accessible via a web browser. This command is typically run from the Julia REPL after the application has been set up and configured. ```julia julia> up() ``` -------------------------------- ### Add Database Adapter for SearchLight Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Installs a specific database adapter package for SearchLight. This example adds the SQLite adapter. Replace `SearchLightSQLite` with the appropriate package for your chosen database (e.g., `SearchLightMySQL`, `SearchLightPostgreSQL`). ```julia pkg> add SearchLightSQLite ``` -------------------------------- ### Start Genie Server (Up) Source: https://genieframework.github.io/Genie.jl/dev/API/server Starts the Genie web server and optionally the WebSocket server. Allows configuration of port, host, and whether to run asynchronously. Returns a collection of the running servers. ```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 Starts the web server. **Arguments** * `port::Int` : the port used by the web server * `host::String`: the host used by the web server * `ws_port::Int`: the port used by the Web Sockets server * `async::Bool`: run the web server task asynchronously **Examples** ```julia julia> up(8000, "127.0.0.1", async = false) [ Info: Ready! Web Server starting at http://127.0.0.1:8000 ``` ``` -------------------------------- ### Setup Database Connection Configuration Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Generates and configures the database connection file (`db/connection.yml`) for Genie and SearchLight. This example uses SQLite with the database file located at `db/books.sqlite`. ```julia julia> Genie.Generator.db_support() ``` ```yaml env: ENV["GENIE_ENV"] dev: adapter: SQLite database: db/books.sqlite config: ``` -------------------------------- ### Create New Genie App using Generator - Julia Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps This code snippet demonstrates how to generate a new Genie application using the `Genie.Generator.newapp` function. It creates a new directory for the app, installs dependencies, sets up a Julia project, and starts the web server. This is the initial step for developing a Genie web application. ```julia julia> Genie.Generator.newapp("MyGenieApp") ``` -------------------------------- ### Install and Configure Docker on EC2 Source: https://genieframework.github.io/Genie.jl/dev/guides/Deploying_Genie_Apps_On_AWS These commands install Docker on an Amazon Linux 2 EC2 instance, add the 'ec2-user' to the 'docker' group for permissions, enable the Docker service to start on boot, and start the Docker service. Verify the installation with 'systemctl status 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 ``` -------------------------------- ### Generate Windows REPL/Server Scripts Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Generates the `repl.bat` and `server.bat` scripts for Windows. These scripts are used to start interactive REPL sessions or server sessions, respectively. ```julia using Genie Genie.Generator.setup_windows_bin_files() ``` -------------------------------- ### Start Genie App Server (Non-Interactive) Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Executes the `bin/server` script to start a Genie web server in non-interactive mode on macOS or Linux. This bypasses the interactive REPL. ```shell $ bin/server ``` -------------------------------- ### Setup Nix Binaries with Setup_nix_bin_files Source: https://genieframework.github.io/Genie.jl/dev/API/generator Creates the `bin/server` and `bin/repl` executable files for *nix-based systems within a Genie project. It takes an optional path to the project directory. ```julia setup_nix_bin_files(path::String = " .") :: Nothing ``` -------------------------------- ### Create and Deploy Genie.jl App using Docker (Example) Source: https://genieframework.github.io/Genie.jl/dev/tutorials/16--Using_Genie_With_Docker This example demonstrates the complete workflow of creating a new Genie.jl app, generating its Dockerfile, building the Docker container, and running the app within the container. It showcases the practical application of the `GenieDeployDocker` plugin. ```julia julia> using Genie julia> Genie.Generator.newapp("DockerTest") [ Info: Done! New app created at /your/app/path/DockerTest # output truncated julia> using GenieDeployDocker julia> GenieDeployDocker.dockerfile() Docker file successfully written at /your/app/path/DockerTest/Dockerfile julia> GenieDeployDocker.build() # output truncated Successfully tagged genie:latest Docker container successfully built julia> GenieDeployDocker.run() Starting docker container with `docker run -it --rm -p 80:8000 --name genieapp genie bin/server` # output truncated ``` -------------------------------- ### Install GenieAuthentication Plugin Files (Julia REPL) Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4-1--Developing_MVC_Web_Apps This command installs the necessary files for the GenieAuthentication plugin into your project. It uses the `@__DIR__` macro to specify the current directory as the installation location. ```julia julia> GenieAuthentication.install(@__DIR__) ``` -------------------------------- ### Setup Windows Binaries with Setup_windows_bin_files Source: https://genieframework.github.io/Genie.jl/dev/API/generator Creates the `bin/server` and `bin/repl` executable files for Windows systems within a Genie project. It takes an optional path to the project directory. ```julia setup_windows_bin_files(path::String = " .") :: Nothing ``` -------------------------------- ### Install Genie Plugin Source: https://genieframework.github.io/Genie.jl/dev/guides/Genie_Plugins Installs a Genie plugin into an existing Genie application. This operation copies necessary files like controllers, views, and initializers into the app structure. It should typically be run only once after adding the plugin. ```julia julia> HelloPlugin.install(@__DIR__) ``` -------------------------------- ### Start Genie Web Server Source: https://genieframework.github.io/Genie.jl/dev/API/genie Starts the Genie web server, aliasing `Server.up`. It allows configuration of the port, host, and websocket port. An option to run the web server task asynchronously is also available. The function returns `Nothing` and provides feedback on the server status. ```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) :: Nothing ``` ```julia julia> up(8000, "127.0.0.1", async = false) [ Info: Ready! Web Server starting at http://127.0.0.1:8000 ``` -------------------------------- ### Run Genie Interactively: Basic Hello World Source: https://genieframework.github.io/Genie.jl/dev/tutorials/3--Getting_Started Configure a routing function and start the web server at the REPL or in a notebook. The `route` function maps a URL to a Julia handler function. The first response might be slower due to Julia's JIT compilation. ```julia julia> using Genie julia> route("/hello") do "Hello World" end julia> up() ``` -------------------------------- ### Julia show Function Example Source: https://genieframework.github.io/Genie.jl/dev/API/router Demonstrates the usage of the 'show' function in Julia, which writes a text representation of a value 'x' to an output stream 'io'. It also shows how 'print' differs and mentions overloading 'show' for custom types and MIME types. Includes examples for string output. ```julia show([io::IO = stdout], x) ``` ```julia julia> show("Hello World!") "Hello World!" julia> print("Hello World!") Hello World! ``` -------------------------------- ### Install Certbot for Nginx on Ubuntu Source: https://genieframework.github.io/Genie.jl/dev/tutorials/92--Deploying_Genie_Server_Apps_with_Nginx Installs the Certbot utility using snap packages, which is required for obtaining and managing SSL certificates for Nginx. This process ensures that Certbot is available system-wide. ```bash sudo snap install core; sudo snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot ``` -------------------------------- ### Get Package Information Source: https://genieframework.github.io/Genie.jl/dev/API/configuration Retrieves information about an installed package specified by its name. This function is useful for introspection and dependency management. ```julia pkginfo(pkg::String) ``` -------------------------------- ### Setup Base Request Parameters Source: https://genieframework.github.io/Genie.jl/dev/API/router Populates the `params` dictionary with essential environment variables and default settings for the current request-response cycle. This is a foundational step for request processing. ```julia function setup_base_params(req::Request, res::Response, params::Dict{Symbol,Any}) :: Dict{Symbol,Any} # Implementation for setting up base params end ``` -------------------------------- ### Create Basic REST API with Genie.jl Source: https://genieframework.github.io/Genie.jl/dev/guides/Simple_API_backend This snippet demonstrates how to set up a simple REST API backend using Genie.jl. It configures the server to run synchronously and defines a root route that returns a JSON message. The server is started using the `up()` function. ```julia using Genie import Genie.Renderer.Json: json Genie.config.run_as_server = true route("/") do (:message => "Hi there!") |> json end up() ``` -------------------------------- ### Install Git and Clone Repository on EC2 Source: https://genieframework.github.io/Genie.jl/dev/guides/Deploying_Genie_Apps_On_AWS Installs Git on the EC2 instance if it's not already present, and then clones a specified Git repository. Replace '' with the URL of your Genie application's Git repository. Navigate into the cloned repository directory. ```bash sudo yum install git -y git clone cd ``` -------------------------------- ### Clone and Set Up Genie App Source: https://genieframework.github.io/Genie.jl/dev/tutorials/92--Deploying_Genie_Server_Apps_with_Nginx Clone the Genie application from a Git repository and install its dependencies using Julia's package manager. This prepares the application environment on the server. ```bash git clone github.com/user/MyGenieApp cd MyGenieAp julia ] activate . pkg> instantiate exit() ``` -------------------------------- ### Activate Local Environment in REPL Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Enters the package manager mode in Julia's REPL and activates the local package environment for the current project. This is a prerequisite for loading the Genie app. ```julia julia> ] # enter pkg> mode pkg> activate . ``` -------------------------------- ### Julia show Function with MIME Type Example Source: https://genieframework.github.io/Genie.jl/dev/API/router Illustrates overloading the 'show' function in Julia to handle different MIME types for displaying objects. It shows how to define a method for 'show(io, ::MIME"text/plain", x::T)' and provides an example of a custom 'Day' type with a specific 'text/plain' representation. ```julia show(io::IO, mime, x) ``` ```julia struct Day n::Int end Base.show(io::IO, ::MIME"text/plain", d::Day) = print(io, d.n, " day") Day(1) ``` ```julia 1 day ``` -------------------------------- ### Install App Dependencies with install_app_dependencies Source: https://genieframework.github.io/Genie.jl/dev/API/generator The `install_app_dependencies` function installs the application's dependencies using Julia's built-in package manager (Pkg). This ensures that all required libraries are available for the application to run correctly. ```julia `Genie.Generator.install_app_dependencies` — Function ``` install_app_dependencies(app_path::String = ".") :: Nothing ``` Installs the application's dependencies using Julia's Pkg source ``` -------------------------------- ### Activate Local Environment and Load Genie App Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Activates the local package environment and loads the Genie app within a Julia REPL, Jupyter, Pluto, or VSCode environment. This ensures all necessary packages are available. ```julia using Pkg Pkg.activate(".") using Genie Genie.loadapp() ``` -------------------------------- ### Launch Genie App Source: https://genieframework.github.io/Genie.jl/dev/tutorials/92--Deploying_Genie_Server_Apps_with_Nginx Start the Genie application using its server script. The application will run in the background within a screen session, accessible at the specified port. ```bash ./bin/server ``` -------------------------------- ### Bootstrap a New Genie Web Service Project Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4--Developing_Web_Services This snippet demonstrates how to create a new Genie web service project named 'MyGenieApp'. It utilizes the `Genie.Generator.newapp_webservice` function to set up the project structure, dependencies, and a basic web server configuration. The process involves creating a new directory, installing necessary Julia packages, and preparing the application for development. ```julia using Genie Genie.Generator.newapp_webservice("MyGenieApp") ``` -------------------------------- ### Create New Genie App Source: https://genieframework.github.io/Genie.jl/dev/guides/Genie_Plugins Generates a new Genie application with the specified name. The `autostart = false` parameter prevents the application server from starting automatically, allowing for further configuration before launch. ```julia julia> Genie.Generator.newapp("Greetings", autostart = false) ``` -------------------------------- ### Setup Resource Path with Setup_resource_path Source: https://genieframework.github.io/Genie.jl/dev/API/generator Computes and creates the directory structure required for persisting a new resource within a Genie application. It takes the resource name as input. ```julia setup_resource_path(resource_name::String) :: String ``` -------------------------------- ### Bootstrap Genie App Loading with Genie.Loader.bootstrap Source: https://genieframework.github.io/Genie.jl/dev/API/loader Initiates the loading sequence for a Genie application by loading the environment settings. This function is crucial for starting up the application. ```julia Genie.Loader.bootstrap(context::Union{Module,Nothing} = nothing) :: Nothing ``` -------------------------------- ### Setup Database Support with db_support Source: https://genieframework.github.io/Genie.jl/dev/API/generator The `db_support` function writes the necessary files for interacting with the SearchLight ORM. This function is crucial for applications that require database integration. ```julia `Genie.Generator.db_support` — Function ``` db_support(app_path::String = ".") :: Nothing ``` Makes the files used for interacting with the SearchLight ORM. source ``` -------------------------------- ### Prepare View Build Directory in Julia Source: https://genieframework.github.io/Genie.jl/dev/API/renderer The `preparebuilds` function sets up the necessary build folder and the main build module file required for generating compiled views. It returns `true` upon successful setup. ```julia preparebuilds() :: Bool ``` -------------------------------- ### Load Genie App with Specific Path Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Loads a Genie app by explicitly providing the path to the app's folder. This is an alternative to `Genie.loadapp()` when the current working directory is not the app's root. ```julia Genie.loadapp("path/to/your/Genie/project") ``` -------------------------------- ### Auto-start App Configuration with autostart_app Source: https://genieframework.github.io/Genie.jl/dev/API/generator The `autostart_app` function configures whether a newly generated Genie app should be automatically started. This setting is typically controlled during the app generation process. ```julia `Genie.Generator.autostart_app` — Function ``` autostart_app(path::String = "."; autostart::Bool = true) :: Nothing ``` If `autostart` is `true`, the newly generated Genie app will be automatically started. source ``` -------------------------------- ### Generate Scripts with Custom Path Source: https://genieframework.github.io/Genie.jl/dev/tutorials/10--Loading_Genie_Apps Allows specifying a custom path for generating Genie application scripts (Windows or *nix). This is useful when the scripts are not in the root Genie project directory. ```julia Genie.Generator.setup_windows_bin_files("path/to/your/Genie/project") Genie.Generator.setup_nix_bin_files("path/to/your/Genie/project") ``` -------------------------------- ### Start Genie Application Source: https://genieframework.github.io/Genie.jl/dev/API/genie Loads an existing Genie application from the file system into the current Julia REPL session. It can optionally auto-start the application upon loading. Dependencies include the Genie framework itself. The function takes a file path and a boolean for auto-starting as input. ```julia using Genie Genie.loadapp(".") ``` -------------------------------- ### Handle query parameters including initial values Source: https://genieframework.github.io/Genie.jl/dev/guides/Interactive_environment Shows how to access query parameters from a URL (e.g., '?foo=bar'). This example extends the route sum functionality to include an optional 'initial_value' query parameter, demonstrating how to safely retrieve and parse it with a default value. ```julia route("/sum/:x::Int/:y::Int") do params(:x) + params(:y) + parse(Int, get(params, :initial_value, "0")) end ``` -------------------------------- ### Execute Random Database Query with SearchLight Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Demonstrates executing a raw SQL query against the database using SearchLight's `query` function. This example retrieves the names of all tables in the SQLite database. ```julia julia> SearchLight.query("SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%'") ┌ Info: SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%' └ 1×1 DataFrames.DataFrame │ Row │ name │ │ │ String⍰ │ ├─────┼───────────────────┤ │ 1 │ schema_migrations │ ``` -------------------------------- ### Test Seed Function and Retrieve Data in Julia REPL Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps These Julia REPL commands demonstrate how to test the 'seed' function and retrieve inserted data. It shows importing the Books module, calling the 'seed' function, and then using SearchLight to fetch all 'Book' records, with output examples including SQL queries and retrieved book data. ```julia julia> using MyGenieApp.Books julia> Books.seed() ``` ```julia julia> using SearchLight julia> all(Book) ``` -------------------------------- ### Example Directory Structure (Default Load Order) Source: https://genieframework.github.io/Genie.jl/dev/guides/Controlling_Load_Order_Of_Genie_Apps Illustrates the default alphabetical loading sequence for .jl files in Genie App directories. ```text Aab.jl Abb.jl Dde.jl Zyx.jl ``` -------------------------------- ### Get Embedded File Path (Genie.jl) Source: https://genieframework.github.io/Genie.jl/dev/API/assets Returns the path to a file relative to Genie's root package directory. This is useful for referencing files within the Genie framework itself or its installed packages. ```julia embedded_path(path::String) :: String ``` -------------------------------- ### Setup MVC Support with mvc_support Source: https://genieframework.github.io/Genie.jl/dev/API/generator The `mvc_support` function writes the files required for rendering resources using the MVC stack and Genie's templating system. This function is essential for applications employing the Model-View-Controller architectural pattern. ```julia `Genie.Generator.mvc_support` — Function ``` mvc_support(app_path::String = ".") :: Nothing ``` Makes the files used for rendering resources using the MVC stack and the Genie templating system. source ``` -------------------------------- ### Load SearchLight Configuration and Connect to Database Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Loads the SearchLight configuration from `db/connection.yml` and establishes a connection to the database. Requires `SearchLight` and the specific database adapter (e.g., `SearchLightSQLite`) to be loaded. ```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 ``` -------------------------------- ### Add Database Support with SearchLight ORM Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4--Developing_Web_Services This command shows how to integrate database support into a Genie application by adding the SearchLight ORM. Executing `Genie.Generator.db_support()` within the app's REPL will install and configure SearchLight, enabling database interactions for the project. ```julia Genie.Generator.db_support() ``` -------------------------------- ### Develop Simple Genie Script: Multiple Routes and Renderers Source: https://genieframework.github.io/Genie.jl/dev/tutorials/3--Getting_Started Create a Genie web service script with multiple routes serving different content types (HTML, JSON, plain text). Uses `html`, `json` renderers and the generic `respond` function. The `up` function is called with `async = false` to keep the script running. ```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) ``` -------------------------------- ### Default Genie Plugin Installation Function Source: https://genieframework.github.io/Genie.jl/dev/guides/Genie_Plugins This Julia function, typically placed in the main plugin module file (`src/GenieHelloPlugin.jl`), is responsible for copying the plugin's files into a Genie application. It iterates through the files in the plugin's `files/` directory and uses `GeniePlugins.install` to perform the copy operation. The `dest` parameter specifies the root directory of the Genie app. ```julia function install(dest::String; force = false) src = abspath(normpath(joinpath(@__DIR__, "..", GeniePlugins.FILES_FOLDER))) for f in readdir(src) isdir(f) || continue GeniePlugins.install(joinpath(src, f), dest, force = force) end end ``` -------------------------------- ### Define a Julia Module in lib/ Source: https://genieframework.github.io/Genie.jl/dev/tutorials/9--Publishing_Your_Julia_Code_Online_With_Genie_Apps Shows an example of a Julia module (`MyLib.jl`) placed within the `lib/` folder. This module defines a function `isitfriday()` that checks if the current day is Friday. Genie automatically loads such modules. ```julia # lib/MyLib.jl module MyLib using Dates function isitfriday() Dates.dayofweek(Dates.now()) == Dates.Friday end end ``` -------------------------------- ### Create lib/ Folder in Julia Source: https://genieframework.github.io/Genie.jl/dev/tutorials/15--The_Lib_Folder Demonstrates how to create the `lib/` folder if it does not exist using a Julia command. ```julia julia> mkdir("lib") ``` -------------------------------- ### Initialize SearchLight Database Migrations Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Initializes the database schema migrations for SearchLight by creating the `schema_migrations` table if it does not exist. This table tracks the status of database schema changes. ```julia julia> SearchLight.Migrations.init() [ Info: Created table schema_migrations ``` -------------------------------- ### Genie.Server.handle_ws_request Source: https://genieframework.github.io/Genie.jl/dev/API/server Http server handler function - invoked when the server gets a request. ```APIDOC ## Genie.Server.handle_ws_request ### Description Http server handler function - invoked when the server gets a request. ### Method `handle_ws_request` ### Parameters - **req** (HTTP.Request) - The incoming HTTP request. - **msg** (String) - The message received from the client. - **ws_client** - The WebSocket client object. ### Returns `String` - The response message to be sent back to the client. ``` -------------------------------- ### Genie.Server.handle_request Source: https://genieframework.github.io/Genie.jl/dev/API/server Http server handler function - invoked when the server gets a request. ```APIDOC ## Genie.Server.handle_request ### Description Http server handler function - invoked when the server gets a request. ### Method `handle_request` ### Parameters - **req** (HTTP.Request) - The incoming HTTP request. - **res** (HTTP.Response) - The HTTP response object. ### Returns `HTTP.Response` - The processed HTTP response. ``` -------------------------------- ### GET /filespayload Source: https://genieframework.github.io/Genie.jl/dev/API/requests Returns a collection of form-uploaded files. ```APIDOC ## GET /filespayload ### Description Collection of form uploaded files. ### Method GET ### Endpoint /filespayload ### Parameters ### Response #### Success Response (200) - **files** (Dict{String, HttpFile}) - A dictionary where keys are file names or input names and values are HttpFile objects. #### Response Example ```json { "file1.txt": { "filename": "file1.txt", "content_type": "text/plain", "size": 1024 } } ``` ``` -------------------------------- ### GET /rawpayload Source: https://genieframework.github.io/Genie.jl/dev/API/requests Returns the raw POST payload as a String. ```APIDOC ## GET /rawpayload ### Description Returns the raw `POST` payload as a `String`. ### Method GET ### Endpoint /rawpayload ### Parameters ### Response #### Success Response (200) - **raw_payload** (String) - The raw payload of the POST request. #### Response Example ``` "This is the raw POST payload." ``` ``` -------------------------------- ### Clone Sample Genie App for Heroku Source: https://genieframework.github.io/Genie.jl/dev/tutorials/90--Deploying_With_Heroku_Buildpacks Clone a sample Genie application repository from GitHub. This provides a base project for deployment. The repository contains a Procfile for Heroku deployment. ```git git clone https://github.com/milesfrain/GenieOnHeroku.git cd GenieOnHeroku ``` -------------------------------- ### Genie.Server.update_config Source: https://genieframework.github.io/Genie.jl/dev/API/server Updates the corresponding Genie configurations to the corresponding values for `port`, `host`, and `ws_port`, if these are passed as arguments when starting up the server. ```APIDOC ## Genie.Server.update_config ### Description Updates the corresponding Genie configurations to the corresponding values for `port`, `host`, and `ws_port`, if these are passed as arguments when starting up the server. ### Method `update_config` ### Parameters - **port** (Int) - The new port for the web server. - **host** (String) - The new host for the web server. - **ws_port** (Int) - The new port for the WebSocket server. ### Returns `Nothing` ``` -------------------------------- ### GET /filespayload(filename) Source: https://genieframework.github.io/Genie.jl/dev/API/requests Returns the HttpFile uploaded through the specified key input name. ```APIDOC ## GET /filespayload/{filename} ### Description Returns the `HttpFile` uploaded through the `key` input name. ### Method GET ### Endpoint /filespayload/{filename} ### Parameters #### Path Parameters - **filename** (String | Symbol) - The key or name of the uploaded file. ### Response #### Success Response (200) - **uploaded_file** (HttpFile) - The HttpFile object corresponding to the given filename. #### Response Example ```json { "filename": "uploaded_image.jpg", "content_type": "image/jpeg", "size": 204800 } ``` ``` -------------------------------- ### Get Response Content-Type Source: https://genieframework.github.io/Genie.jl/dev/API/router Determines and returns the content type for the current response. This is important for setting the `Content-Type` header correctly. ```julia function response_type{T}(params::Dict{Symbol,T}) :: Symbol # Implementation to get response type end ``` ```julia function response_type(params::Params) :: Symbol # Implementation to get response type end ``` -------------------------------- ### Get Request Content-Type Source: https://genieframework.github.io/Genie.jl/dev/API/router Extracts the content type of an HTTP request. This function helps in understanding the format of the data sent by the client. ```julia function request_type(req::HTTP.Request) :: Symbol # Implementation to get request type end ``` -------------------------------- ### Get Request Content-Length Source: https://genieframework.github.io/Genie.jl/dev/API/router Retrieves the content length of an HTTP request. This is useful for determining the size of the data being sent in the request body. ```julia function content_length(req::HTTP.Request) :: Int # Implementation to get content length end ``` -------------------------------- ### Load SearchLight Database Initializer Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4-1--Developing_MVC_Web_Apps This Julia command includes the SearchLight database initializer file. This is necessary to load and apply the database configuration defined in `db/connection.yml`. ```julia julia> include(joinpath("config", "initializers", "searchlight.jl")) ``` -------------------------------- ### Get File Extension Source: https://genieframework.github.io/Genie.jl/dev/API/router Extracts and returns the file extension from a given file name or path string. This is helpful for identifying file types. ```julia function file_extension(f) :: String # Implementation to get file extension end ``` -------------------------------- ### Get and Render HTML Template Source: https://genieframework.github.io/Genie.jl/dev/API/renderer-html Resolves the inclusion and rendering of a template file. It can optionally render partial templates and specify a context module and variables. ```julia get_template(path::String; partial::Bool = true, context::Module = @__MODULE__, vars...) :: Function ``` -------------------------------- ### Genie.Server.setup_http_listener Source: https://genieframework.github.io/Genie.jl/dev/API/server Configures the handler for the HTTP Request and handles errors. ```APIDOC ## Genie.Server.setup_http_listener ### Description Configures the handler for the HTTP Request and handles errors. ### Method `setup_http_listener` ### Parameters - **req** (HTTP.Request) - The incoming HTTP request. - **res** (HTTP.Response) - The HTTP response object. Defaults to an empty `HTTP.Response()`. ### Returns `HTTP.Response` - The configured HTTP response. ``` -------------------------------- ### GET /infilespayload(key) Source: https://genieframework.github.io/Genie.jl/dev/API/requests Checks if the collection of uploaded files contains a file stored under the specified key name. ```APIDOC ## GET /infilespayload/{key} ### Description Checks if the collection of uploaded files contains a file stored under the `key` name. ### Method GET ### Endpoint /infilespayload/{key} ### Parameters #### Path Parameters - **key** (String | Symbol) - The name or key to check for in the uploaded files. ### Response #### Success Response (200) - **has_file** (Bool) - True if a file with the specified key exists, false otherwise. #### Response Example ```json true ``` ``` -------------------------------- ### Create New Web Service Genie App with Newapp_webservice Source: https://genieframework.github.io/Genie.jl/dev/API/generator Scaffolds a new Genie application suitable for nimble web services. It supports autostart and can optionally include database support by specifying a `dbadapter`. If `dbadapter` is not provided, it will be selected interactively. ```julia newapp_webservice(name::String; autostart::Bool = true, dbsupport::Bool = false, dbadapter::Union{String,Symbol,Nothing} = nothing) :: Nothing ``` -------------------------------- ### Prepare HTML Template for Rendering Source: https://genieframework.github.io/Genie.jl/dev/API/renderer-html Cleans up a template string or vector before rendering, for example, by removing empty nodes. Accepts either a String or a Vector of any type. ```julia prepare_template(s::String) prepare_template{T}(v::Vector{T}) ``` -------------------------------- ### Get Response MIME Type Source: https://genieframework.github.io/Genie.jl/dev/API/router Returns the MIME type that will be used for the response. This helps in setting the `Content-Type` header appropriately based on the response content. ```julia function response_mime() # Implementation to get response MIME type end ``` -------------------------------- ### Update Genie Server Configuration Source: https://genieframework.github.io/Genie.jl/dev/API/server Allows updating the configuration for the web server port, host, and WebSocket port. This is typically used when starting the server with specific parameters. ```julia update_config(port::Int, host::String, ws_port::Int) :: Nothing Updates the corresponding Genie configurations to the corresponding values for `port`, `host`, and `ws_port`, if these are passed as arguments when starting up the server. ``` -------------------------------- ### Throw ExceptionalResponse for Unauthorized Access in Julia Source: https://genieframework.github.io/Genie.jl/dev/API/exceptions Example of throwing an `ExceptionalResponse` when a user is not authenticated. If not caught, Genie handles the exception by sending a redirect response to the login page. ```julia isauthenticated() || throw(ExceptionalResponse(redirect(:show_login))) ``` -------------------------------- ### Define a Simple Route in Genie.jl Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4--Developing_Web_Services This code defines a basic route for a Genie web service. When a user visits the '/hello' endpoint, the application will respond with the text 'Welcome to Genie!'. This illustrates how to register simple URL routes and their corresponding handlers within the `routes.jl` file. ```julia route("/hello") do "Welcome to Genie!" end ``` -------------------------------- ### Send Endpoint (GET /send) Source: https://genieframework.github.io/Genie.jl/dev/guides/Simple_API_backend This endpoint makes an HTTP POST request to the /echo endpoint with a predefined JSON payload and returns the response. ```APIDOC ## GET /send ### Description This endpoint simulates sending a request to the `/echo` service. It makes an HTTP POST request to `http://localhost:8000/echo` with a JSON payload and returns the response received from the echo service. ### Method GET ### Endpoint /send ### Parameters None ### Request Example None ### Response #### Success Response (200) - **echo** (string) - The echoed and repeated message from the `/echo` endpoint. #### Response Example ```json { "echo": "hello hello hello " } ``` ``` -------------------------------- ### Get JavaScript Asset Path (Genie.jl) Source: https://genieframework.github.io/Genie.jl/dev/API/assets Retrieves the file path for a JavaScript asset. The function takes the file name as a string, excluding the `.js` extension. ```julia js_asset(file_name::String) :: String ``` -------------------------------- ### Simple Root Endpoint Source: https://genieframework.github.io/Genie.jl/dev/guides/Simple_API_backend Sets up a basic API endpoint at the root path '/' that returns a JSON message. ```APIDOC ## GET / ### Description This endpoint serves as a simple "hello world" for the API, returning a JSON object with a greeting message. ### Method GET ### Endpoint / ### Parameters None ### Request Example None ### Response #### Success Response (200) - **message** (string) - A greeting message. #### Response Example ```json { "message": "Hi there!" } ``` ``` -------------------------------- ### Scaffold a New Genie Plugin Project Source: https://genieframework.github.io/Genie.jl/dev/guides/Genie_Plugins This code snippet demonstrates how to use GeniePlugins.jl to scaffold a new Genie plugin. It requires the Genie and GeniePlugins packages to be loaded. The command generates the necessary project files, directory structure, and initializes a Git repository for the new plugin. ```julia using Genie, GeniePlugins GeniePlugins.scaffold("GenieHelloPlugin") # use the actual name of your plugin ``` -------------------------------- ### Serve Static Files with Genie Source: https://genieframework.github.io/Genie.jl/dev/API/server Configures Genie to serve static files from a specified directory, effectively turning Genie into a static file web server. Additional parameters are forwarded to `Genie.up()`. ```julia serve(path::String = pwd(), params...; kwparams...) Serves a folder of static files located at `path`. Allows Genie to be used as a static files web server. The `params` and `kwparams` arguments are forwarded to `Genie.up()`. **Arguments** * `path::String` : the folder of static files to be served by the server * `params`: additional arguments which are passed to `Genie.up` to control the web server * `kwparams`: additional keyword arguments which are passed to `Genie.up` to control the web server **Examples** ```julia julia> Genie.serve("public", 8888, async = false, verbose = true) [ Info: Ready! 2019-08-06 16:39:20:DEBUG:Main: Web Server starting at http://127.0.0.1:8888 [ Info: Listening on: 127.0.0.1:8888 [ Info: Accept (1): 🔗 0↑ 0↓ 1s 127.0.0.1:8888:8888 ≣16 ``` ``` -------------------------------- ### Example .autoload File Content Source: https://genieframework.github.io/Genie.jl/dev/guides/Controlling_Load_Order_Of_Genie_Apps Demonstrates the content of a `.autoload` file to define a custom load order, including file exclusion. ```text --x-yz.jl def.jl Abc.jl -Foo.jl ``` -------------------------------- ### Create Views Directory (Julia) Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Creates a directory structure for view files within an application's resources. Uses joinpath for cross-platform compatibility. ```julia mkdir(joinpath("app", "resources", "books", "views")) ``` -------------------------------- ### Example Directory Structure (Custom Load Order) Source: https://genieframework.github.io/Genie.jl/dev/guides/Controlling_Load_Order_Of_Genie_Apps Shows a directory with .jl files before applying custom load order configurations. ```text Aaa.jl Abb.jl Abc.jl def.jl Foo.jl -x-yz.jl ``` -------------------------------- ### Get File Headers Source: https://genieframework.github.io/Genie.jl/dev/API/router Retrieves a dictionary of HTTP headers suitable for a given file. This is commonly used when serving static files to set `Content-Type` and other relevant headers. ```julia function file_headers(f) :: Dict{String,String} # Implementation to get file headers end ``` -------------------------------- ### Get Resource File Path (Alias) Source: https://genieframework.github.io/Genie.jl/dev/API/router An alias for `file_path`, this function also constructs the full file system path for a resource, with options to include the document root. ```julia function filepath(resource::String; within_doc_root = true, root = Genie.config.server_document_root) :: String # Implementation to get file path (alias) end ``` -------------------------------- ### Access Server via SSH Source: https://genieframework.github.io/Genie.jl/dev/tutorials/92--Deploying_Genie_Server_Apps_with_Nginx Connect to your server instance using SSH. Ensure you have the correct private key and user credentials. This is the initial step to manage your server environment. ```bash ssh -i "ssh-key-for-instance.pem" user@123.123.123.123 ``` -------------------------------- ### Get Current Genie Environment Source: https://genieframework.github.io/Genie.jl/dev/API/configuration Returns a string representing the current Genie environment (e.g., 'dev', 'prod', 'test'). This is useful for conditional logic based on the running environment. ```julia env() :: String # Example: # Configuration.env() ``` -------------------------------- ### Initialize SearchLight Migrations Table Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4-1--Developing_MVC_Web_Apps This command initializes the necessary database table for SearchLight's migration system. It allows Genie to track and manage database schema changes. ```julia julia> SearchLight.Migration.init() ``` -------------------------------- ### Genie.Server.setup_ws_handler Source: https://genieframework.github.io/Genie.jl/dev/API/server Configures the handler for WebSockets requests. ```APIDOC ## Genie.Server.setup_ws_handler ### Description Configures the handler for WebSockets requests. ### Method `setup_ws_handler` ### Parameters - **stream** (HTTP.Stream) - The HTTP stream for the WebSocket connection. - **ws_client** - The WebSocket client object. ### Returns `Nothing` ``` -------------------------------- ### Map a complex URI to a predefined function Source: https://genieframework.github.io/Genie.jl/dev/guides/Interactive_environment Demonstrates mapping a more complex URL path to a pre-existing Julia function. The function `hello_world` is defined and then associated with the '/hello/world' route. The route handler function can reside in any accessible scope. ```julia function hello_world() "Hello World!" end route("/hello/world", hello_world) ``` -------------------------------- ### Genie.Router: Parameter Conversion and Extraction Source: https://genieframework.github.io/Genie.jl/dev/API/router Functions for converting route parameters to a dictionary and extracting various types of parameters from requests, including URI, GET, POST, and JSON payloads. ```julia source`Genie.Router.route_params_to_dict` — Function ``` route_params_to_dict(route_params) ``` Converts the route params to a `Dict`. source`Genie.Router.action_controller_params` — Function ``` action_controller_params(action::Function, params::Params) :: Nothing ``` Sets up the :action_controller, :action, and :controller key - value pairs of the `params` collection. source`Genie.Router.extract_uri_params` — Function ``` extract_uri_params(uri::String, regex_route::Regex, param_names::Vector{String}, param_types::Vector{Any}, params::Params) :: Bool ``` Extracts params from request URI and sets up the `params` `Dict`. source`Genie.Router.extract_get_params` — Function ``` extract_get_params(uri::URI, params::Params) :: Bool ``` Extracts query vars and adds them to the execution `params` `Dict`. source`Genie.Router.extract_post_params` — Function ``` extract_post_params(req::Request, params::Params) :: Nothing ``` Parses POST variables and adds the to the `params` `Dict`. source`Genie.Router.extract_request_params` — Function ``` extract_request_params(req::HTTP.Request, params::Params) :: Nothing ``` Sets up the `params` key-value pairs corresponding to a JSON payload. ``` -------------------------------- ### Create View Partial File (Julia) Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps_Intermediary_Topics This snippet demonstrates how to create a new view partial file using the `touch` command in Julia. View partials are separate files that contain reusable HTML snippets, making templates cleaner and more organized. This command creates an empty file at the specified path, ready to be populated with view content. ```julia touch("app/resources/books/views/book.jl.html") ``` -------------------------------- ### Get Favicon Link Tag (Genie.jl) Source: https://genieframework.github.io/Genie.jl/dev/API/assets Generates the HTML `` tag necessary for referencing the favicon file that is embedded within the Genie package. This function requires no arguments. ```julia favicon_support() :: String ``` -------------------------------- ### Define Root Route in Genie Source: https://genieframework.github.io/Genie.jl/dev/tutorials/4-1--Developing_MVC_Web_Apps This code defines a route for the root URL ('/'). When a request is made to the root, it serves the static 'welcome.html' file located in the public directory. ```julia route("/") do serve_static_file("welcome.html") end ``` -------------------------------- ### Get Channels JavaScript File (Genie.jl) Source: https://genieframework.github.io/Genie.jl/dev/API/assets Outputs the `channels.js` file included with the Genie package. This is typically used to enable real-time communication features within a Genie.jl application. ```julia channels(channel::AbstractString = Genie.config.webchannels_default_route) :: String ``` -------------------------------- ### Create Markdown View File Source: https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps Creates a new Markdown view file with the `.jl.md` extension. This is a preparatory step before defining the content of a Markdown view. ```julia julia> touch(joinpath("app", "resources", "books", "views", "billgatesbooks.jl.md")) ``` -------------------------------- ### Get Raw POST Payload - Genie.jl Source: https://genieframework.github.io/Genie.jl/dev/API/requests Retrieves the raw POST payload as a String. This function is useful for inspecting the raw data before or if JSON parsing fails. ```julia rawpayload() :: String ``` -------------------------------- ### Get Resource File Path Source: https://genieframework.github.io/Genie.jl/dev/API/router Constructs the full file system path for a given resource. It can prepend the document root if `within_doc_root` is true, defaulting to Genie's server document root. ```julia function file_path(resource::String; within_doc_root = true, root = Genie.config.server_document_root) :: String # Implementation to get file path end ``` -------------------------------- ### Initialize Genie Application Source: https://genieframework.github.io/Genie.jl/dev/API/genie Initializes the Genie framework. This function is typically called at the beginning of a Genie application's lifecycle to set up the necessary components. ```julia genie() :: Union{Nothing,Sockets.TCPServer} ``` -------------------------------- ### Register Webthreads Push/Pull Routes (Genie.jl) Source: https://genieframework.github.io/Genie.jl/dev/API/assets Registers the necessary routes for handling push and pull operations within a specified channel for web threads. This function is part of the web channel setup. ```julia function webthreads_push_pull(channel) :: Nothing ```