### Quickstart Verification Provider Setup Source: https://hexdocs.pm/plug_sigaws/PlugSigaws.html Configure the quickstart provider for signature verification, including regions, services, and credentials file. ```APIDOC ## Quickstart Verification Provider ### 1. Add to dependencies ```elixir defp deps do {:sigaws_quickstart_provider, "~> 0.1"} end ``` ### 2. Add to supervision tree ```elixir use Application def start(_type, _args) do import Supervisor.Spec children = [ worker(SigawsQuickStartProvider, [[name: :sigaws_provider]]), # .... ] # .... Supervisor.start_link(children, opts) end ``` ### 3. Add configuration to `config.exs` ```elixir config :plug_sigaws, provider: SigawsQuickStartProvider config :sigaws_quickstart_provider, regions: "us-east-1,alpha-quad,beta-quad,gamma-quad,delta-quad", services: "my-service,img-service", creds_file: "sigaws_quickstart.creds" ``` ### Configuration Parameters * `regions` — Set this to a comma separated list of region names. A request signed with a region not in this list will fail. * `services` — Set this to a comma separated list of service names. A request signed with a service not in this list will fail. * `creds_file` — Path to the credentials file. The quickstart provider reads this file to get the list of valid access key IDs and their corresponding secrets. Each line in this file represents a valid credential with a colon separating the access key ID and the secret. ``` -------------------------------- ### Elixir Plug.CGI Example Source: https://hexdocs.pm/plug_cgi/readme.html This example demonstrates how to install plug_cgi, define a simple Plug module, and run it using Plug.CGI.run. Ensure plug_cgi is added as a dependency for this to work. ```elixir #!/usr/bin/env elixir # Install plug_cgi as a dependency Mix.install([ :plug_cgi ]) # Define your plug # You can use middleware, routing, or anything else defmodule MyPlug do import Plug.Conn def init(options) do # initialize options options end def call(conn, _opts) do conn |> put_resp_content_type("text/plain") |> send_resp(200, "Hello world") end end # Run your plug with plug_cgi Plug.CGI.run MyPlug ``` -------------------------------- ### start() Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpJson.html Starts HTTPoison and its dependencies. ```APIDOC ## start() ### Description Starts HTTPoison and its dependencies. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters - None ### Request Example ```elixir HTTPoison.start() ``` ### Response #### Success Response - N/A (Starts the service) #### Response Example - N/A ``` -------------------------------- ### PlugSignature Configuration Examples Source: https://hexdocs.pm/plug_signature/PlugSignature.html Examples demonstrating different ways to configure the PlugSignature plug, including minimal setup, custom headers, legacy algorithms, and mixed algorithm configurations. ```APIDOC ## Minimal Configuration ```elixir plug PlugSignature, callback_module: MyApp.SignatureAuth ``` ## Custom Header Configuration ```elixir plug PlugSignature, callback_module: MyApp.SignatureAuth, headers: "(request-target) (created) host digest" ``` ## Legacy Algorithms with Custom Headers ```elixir plug PlugSignature, callback_module: MyApp.SignatureAuth, algorithms: ["ecdsa-sha256", "rsa-sha256"], headers: "(request-target) date host" ``` ## Mixed Algorithms with Custom Validity ```elixir plug PlugSignature, callback_module: MyApp.SignatureAuth, headers: "(request-target) (expires) host digest", validity: :infinity, legacy: [ headers: "(request-target) date host digest", validity: -300..30, ] ``` ``` -------------------------------- ### Example Usage of Token Bucket Source: https://hexdocs.pm/plug_ratelimit/Buckets.TokenBucket.html Demonstrates starting a token bucket and then checking its emptiness. The `start/1` function creates the bucket, and `empty?/1` tests its state. ```elixir {:ok, pid} = Buckets.TokenBucket.start(10) Buckets.TokenBucket.empty?(pid) ``` -------------------------------- ### Clone Example Project Source: https://hexdocs.pm/plug_graphql/index.html Clone the example project to see a working integration. ```bash git clone https://github.com/graphql-elixir/hello_graphql_phoenix ``` -------------------------------- ### Setup Development Environment Source: https://hexdocs.pm/plug_content_security_policy/index.html Run the setup script to prepare the development environment for PlugContentSecurityPolicy. ```bash bin/setup ``` -------------------------------- ### Configuration Example Source: https://hexdocs.pm/plug_rest/PlugRest.Resource.html Example of how to configure PlugRest globally in `config.exs`. ```APIDOC ## Global Configuration To change the default `known_methods` for all Resources: ```elixir config :plug_rest, known_methods: ["GET", "HEAD", "OPTIONS", "TRACE"] ``` *Note: Resource-specific callbacks take precedence over global configuration.* ``` -------------------------------- ### Define Resource Routes with PlugRest.Router Source: https://hexdocs.pm/plug_rest/PlugRest.Router.html This example shows the basic setup for PlugRest.Router, including the necessary plugs and a resource definition. ```elixir defmodule MyApp.Router do use PlugRest.Router plug :match plug :dispatch resource "/pages/:page", PageResource end ``` -------------------------------- ### Installation and Configuration Source: https://hexdocs.pm/plug_telemetry_server_timing/Plug.Telemetry.ServerTiming.html Instructions on how to install the package and configure it within your Plug application pipeline. ```APIDOC ## Installation The package can be installed by adding `plug_server_timing` to your list of dependencies in `mix.exs`: ```elixir def deps do [ {:plug_telemetry_server_timing, "~> 0.3.0"} ] end ``` Then add `Plug.ServerTiming` to your pipeline **BEFORE** any `Plug.Telemetry` definitions: ```elixir plug Plug.Telemetry.ServerTiming plug Plug.Telemetry, event_prefix: [:my, :plug] ``` ### Important You need to place this plug **BEFORE** `Plug.Telemetry` call as otherwise it will not see it's events (`before_send` callbacks are called in reverse order of declaration, so this one need to be added before `Plug.Telemetry` one. ``` -------------------------------- ### Installation Source: https://hexdocs.pm/plug_shopify_jwt/PlugShopifyEmbeddedJWTAuth.html Instructions on how to install the plug_shopify_jwt package using Mix. ```APIDOC ## Installation ### Description The package can be installed by adding `plug_shopify_jwt` to your list of dependencies in `mix.exs`. ### Code ```elixir def deps do [ {:plug_shopify_jwt, "~> 0.1.0"} ] end ``` ``` -------------------------------- ### Basic Usage Example Source: https://hexdocs.pm/plug_shopify_jwt/PlugShopifyEmbeddedJWTAuth.html A basic setup demonstrating how to integrate PlugShopifyEmbeddedJWTAuth into your Phoenix router pipeline. ```APIDOC ## Basic Usage Example ### Description Grab your app secret and insert `plug PlugShopifyEmbeddedJWTAuth, [secret: "your-secret"]` into your `router.ex` file. A basic setup looks something similar to this: ### Code ```elixir pipeline :embedded do plug PlugShopifyEmbeddedJWTAuth, [secret: "224e5146-4f1e-4a1d-a64a-2732df659542"] end scope "/api", HelloPhoenixWeb do pipe_through :embedded get "/show", PageController, :show end ``` ``` -------------------------------- ### start_link/1 Source: https://hexdocs.pm/plug_amqp/Plug.Amqp.html Starts the Plug.Amqp process, typically used when starting the application under a supervisor. ```APIDOC ## start_link(options \\ []) ### Description Starts the Plug.Amqp process, typically used when starting the application under a supervisor. ### Function Signature ```elixir start_link(options :: Plug.Amqp.options()) :: Supervisor.on_start() ``` ### Parameters * `options` (Plug.Amqp.options()) - A list of options to configure the AMQP connection and plug behavior. Defaults to `[]`. ``` -------------------------------- ### Start HTTP Client Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpJson.html Starts the HTTP client and its dependencies. ```APIDOC ## Start HTTP Client ### Description Starts HTTPoison and its dependencies. ### Function Signature `start()` ### Usage ```elixir PlugCommon.HttpJson.start() ``` ### Response This function typically returns `:ok` on successful startup or an error tuple. ``` -------------------------------- ### Start Phoenix Server Source: https://hexdocs.pm/plug_graphql/index.html Start your Phoenix application server. ```bash mix phoenix.server ``` -------------------------------- ### Module Plug Example Source: https://hexdocs.pm/plug/Plug.html An example of a module plug that implements the `Plug` behavior, exporting `init/1` and `call/2`. ```APIDOC Here's an example of a module plug: ``` defmodule JSONHeaderPlug do @behaviour Plug import Plug.Conn def init(opts) do opts end def call(conn, _opts) do put_resp_content_type(conn, "application/json") end end ``` ``` -------------------------------- ### GET Route Example Source: https://hexdocs.pm/plug/Plug.Router.html A simple GET route that responds with 'world' to requests for '/hello'. ```elixir get "/hello" do send_resp(conn, 200, "world") end ``` -------------------------------- ### Start HTTP Client Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpForm.html Starts the HTTP client and its dependencies. This function should be called before making any requests. ```elixir start() ``` -------------------------------- ### Get Store Name Example Source: https://hexdocs.pm/plug/Plug.Session.Store.html Demonstrates how to get the store name from an atom or module. ```iex iex> Plug.Session.Store.get(CustomStore) CustomStore iex> Plug.Session.Store.get(:cookie) Plug.Session.COOKIE ``` -------------------------------- ### Get! Function Example Source: https://hexdocs.pm/plug_cache/PlugCache.LocalCache.html Demonstrates the usage of `get!/2` which retrieves a value associated with a key or raises a `KeyError` if the key is not found. ```elixir MyCache.get!(:a) ``` -------------------------------- ### start_link/1 Source: https://hexdocs.pm/plug_cache/PlugCache.LocalCache.html Starts the cache process, returning `{:ok, pid}` on success or an error tuple if the cache is already started or another issue occurs. ```APIDOC ## MyCache.start_link(opts \\ []) ### Description Starts a supervision and return `{:ok, pid}` or just `:ok` if nothing needs to be done. Returns `{:error, {:already_started, pid}}` if the cache is already started or `{:error, term}` in case anything else goes wrong. ### Options See the configuration in the moduledoc for options shared between adapters, for adapter-specific configuration see the adapter’s documentation. ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_pubsub/PlugPubsub.Consumer.html Set up queue consumer. ```APIDOC ## init/1 ### Description Set up queue consumer. ### Function Signature init(atom) ``` -------------------------------- ### Custom Cache Profile: Cache GET Requests Only Source: https://hexdocs.pm/plug_response_cache/index.html Implement a custom cache profile to control which requests are cached. This example caches only GET requests by overriding the `cache_request?/2` callback. ```elixir defmodule MyCacheProfile do @behaviour PlugResponseCache.Profile alias Plug.Conn def cache_request?(%Conn{method: "GET"}, _opts), do: true def cache_request?(_conn, _opts), do: false # ... end ``` -------------------------------- ### Hello World Example in Elixir Source: https://hexdocs.pm/plug_zipkin/PlugZipkin.html Demonstrates the basic usage of the hello function from PlugZipkin. ```elixir iex> PlugZipkin.hello :world ``` -------------------------------- ### Pluggy Session Usage Example Source: https://hexdocs.pm/pluggy_ai/Pluggy.Session.html Demonstrates the typical workflow for initializing a session, obtaining a connect token, setting item data, and fetching resources like accounts and transactions. ```elixir client = Pluggy.Client.new("client_id", "client_secret") session = Pluggy.Session.new(client) # Get a connect token for the widget {:ok, token, session} = Pluggy.Session.connect_token(session) # After widget connection completes session = Pluggy.Session.with_item(session, item_data) # Fetch resources {:ok, accounts} = Pluggy.Session.accounts(session) {:ok, txns} = Pluggy.Session.transactions(session, account_id) ``` -------------------------------- ### setup!/0 Source: https://hexdocs.pm/plug_session_mnesia/PlugSessionMnesia.Helpers.html Sets up the Mnesia table for session storage according to configuration, with persistent storage. ```APIDOC ## setup!/0 ### Description Sets up the Mnesia table for session storage based on the application configuration. This function creates a persistent table (data stored in RAM and disk), ensuring sessions survive application reboots. ### Function Signature ```elixir setup!() :: :ok ``` ### Configuration Requires `:table` to be set in `config.exs`: ```elixir config :plug_session_mnesia, table: :session, ``` ### Behavior If the table already exists with different attributes, a `PlugSessionMnesia.TableExists` error is raised. For more details on the setup process, refer to `setup/2`. ``` -------------------------------- ### GET Route with Globbing Source: https://hexdocs.pm/plug/Plug.Router.html Matches any route starting with '/hello' and captures the rest of the path into the '_rest' variable. ```elixir get "/hello/*_rest" do send_resp(conn, 200, "matches all routes starting with /hello") end ``` -------------------------------- ### Set and Get Cache Values Source: https://hexdocs.pm/plug_cache/PlugCache.DistCache.html Demonstrates setting a value in the cache and retrieving it. Includes examples of getting values with invalid versions and different conflict resolution strategies, showing how to retrieve the raw value or a Nebulex.Object. ```elixir 1 = MyCache.set :a, 1 # Gets with an invalid version but do nothing on conflicts. # Keep in mind that, although this returns successfully, the returned # struct does not reflect the data in the Cache. For instance, in case # of "on_conflict: :nothing", it returns the latest version of the # cached object. %Nebulex.Object{key: :a, value: 1} = MyCache.get :a, return: :object, version: :invalid, on_conflict: :nothing 1 = MyCache.get :a # Gets with the same invalid version but force to return `nil` nil = MyCache.get :a, version: :invalid, on_conflict: nil 1 = MyCache.get :a ``` -------------------------------- ### Configure PlugSigaws with Quickstart Provider Source: https://hexdocs.pm/plug_sigaws/PlugSigaws.html Set the `plug_sigaws` application configuration in `config.exs` to use the `SigawsQuickStartProvider` and specify its parameters like regions, services, and credentials file. ```elixir config :plug_sigaws, provider: SigawsQuickStartProvider config :sigaws_quickstart_provider, regions: "us-east-1,alpha-quad,beta-quad,gamma-quad,delta-quad", services: "my-service,img-service", creds_file: "sigaws_quickstart.creds" ``` -------------------------------- ### Basic Plug.Router Definition Source: https://hexdocs.pm/plug/Plug.Router.html Defines a basic router with match and dispatch plugs, and example GET and catch-all routes. ```elixir defmodule AppRouter do use Plug.Router plug :match plug :dispatch get "/hello" do send_resp(conn, 200, "world") end match _ do send_resp(conn, 404, "oops") end end ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_shopify_verify_timestamp/PlugShopifyVerifyTimestamp.html Initializes the plug with given options. ```APIDOC ## init/1 ### Description Initializes the Shopify timestamp verification plug with the provided configuration options. ### Function Signature ```elixir init(options) ``` ### Parameters * `options` (any()) - Configuration options for the plug. ``` -------------------------------- ### GET Route with Globbing to Variable Source: https://hexdocs.pm/plug/Plug.Router.html Matches any route starting with '/hello' and captures the rest of the path into the 'glob' variable as a list. ```elixir get "/hello/*glob" do send_resp(conn, 200, "route after /hello: #{inspect glob}") end ``` -------------------------------- ### Create Pluggy Connect Widget Examples Source: https://hexdocs.pm/pluggy_ai/Pluggy.Connect.Kino.html Demonstrates different ways to initialize the Pluggy Connect widget, either with a client or a connect token string, and with or without sandbox connectors. ```elixir widget = Pluggy.Connect.Kino.new(client) widget = Pluggy.Connect.Kino.new(client, include_sandbox: true) widget = Pluggy.Connect.Kino.new("connect_token_string") ``` -------------------------------- ### Conditional Plug Invocation Source: https://hexdocs.pm/plug/Plug.Builder.html Wrap a module plug in a function plug to conditionally invoke it. This example skips `Plug.Parsers` for routes starting with `/noparser`. ```elixir plug :conditional_parser defp conditional_parser(%Plug.Conn{path_info: ["noparser" | _]} = conn, _opts) do conn end @parser Plug.Parsers.init(parsers: [:urlencoded, :multipart], pass: ["text/*"]) defp conditional_parser(conn, _opts) do Plug.Parsers.call(conn, @parser) end ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_mishka_auth/MishkaAuth.Plug.LoginedCurrentUserPlug.html Initializes the plug with default configuration. ```APIDOC ## init/1 ### Description Initializes the plug with default configuration. ### Function Signature ```elixir init(default) ``` ### Parameters - **default** (any()) - Default configuration for the plug. ### Returns - **any()** - The initialized configuration. ``` -------------------------------- ### Write Resource Test with Plug.Test Source: https://hexdocs.pm/plug_rest/readme.html Example of how to write tests for a PlugRest resource using `Plug.Test`. This test verifies a GET request to the '/hello' resource. ```elixir defmodule MyApp.HelloResourceTest do use ExUnit.Case use Plug.Test alias MyApp.Router test "get hello resource" do conn = conn(:get, "/hello") conn = Router.call(conn, []) assert conn.status == 200 assert conn.resp_body == "Hello world" end end ``` -------------------------------- ### Basic PlugResponseCache Pipeline Setup Source: https://hexdocs.pm/plug_response_cache/index.html Integrate PlugResponseCache into your Phoenix pipeline by adding it as early as possible. The default configuration caches GET requests in ETS. ```elixir pipeline :browser do plug(:accepts, ["html"]) plug(PlugResponseCache) plug(:fetch_session) plug(:fetch_flash) plug(:protect_from_forgery) plug(:put_secure_browser_headers) end ``` -------------------------------- ### Start Cache Link Source: https://hexdocs.pm/plug_cache/PlugCache.DistCache.Local.html Shows the function signature for starting a cache supervision process. It returns {:ok, pid} or :ok on success, and {:error, ...} on failure. ```elixir start_link(opts \\ []) ``` -------------------------------- ### Resource Routing with Globbing (Saved Parameter) Source: https://hexdocs.pm/plug_rest/PlugRest.Router.html This example shows how to use globbing to match all routes starting with a specific path and save the matched segments as a parameter. ```elixir # matches all routes starting with /hello and saves the rest resource "/hello/*rest", HelloResource ``` ```elixir %{"rest" => ["value"]} %{"rest" => ["value", "extra"]} ``` -------------------------------- ### init(default) Source: https://hexdocs.pm/plug_mishka_auth/MishkaAuth.Plug.LoginedCurrentTokenPlug.html Initializes the plug with default configuration. ```APIDOC ## init(default) ### Description Initializes the plug with default configuration. This function is typically called when the plug is first loaded or configured. ### Function Signature ```elixir init(any()) :: any() ``` ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_mishka_auth/MishkaAuth.Plug.RequestPlug.html Initializes the plug with default options. ```APIDOC ## init/1 ### Description Initializes the plug with default options. ### Function Signature ```elixir init(default) ``` ### Parameters - **default** (any()) - Default options for initialization. ### Returns - **any()** - The initialized value. ``` -------------------------------- ### GET /verify Request Example Source: https://hexdocs.pm/plug_gpg_verify/PlugGPGVerify.html This endpoint generates a challenge when a user is found and has a public key configured. It returns a JSON response with the challenge and user ID. ```json { "challenge": "string", "user_id": "string" } ``` -------------------------------- ### Basic PlugProbe Setup in Plug.Builder Source: https://hexdocs.pm/plug_probe/PlugProbe.html Demonstrates how to integrate PlugProbe into a basic Plug.Builder pipeline. Place it before other plugs to ensure early matching of probe requests. ```elixir defmodule DemoServer do use Plug.Builder # Put it before any other plugs plug PlugProbe # ... endcopy ``` -------------------------------- ### PluggyAI Session API Example Source: https://hexdocs.pm/pluggy_ai/index.html Demonstrates creating a client, initiating a session, obtaining a connect token, and fetching accounts and transactions using the `Pluggy.Session` module. ```elixir {:ok, client} = Pluggy.Client.new("client_id", "client_secret") session = Pluggy.Session.new(client) {:ok, token, session} = Pluggy.Session.connect_token(session) # ... user completes Connect flow, returns item_data ... session = Pluggy.Session.with_item(session, item_data) {:ok, accounts} = Pluggy.Session.accounts(session) {:ok, transactions} = Pluggy.Session.transactions(session, account_id) ``` -------------------------------- ### Define Pre Hooks Source: https://hexdocs.pm/plug_cache/PlugCache.LocalCache.html Defines a `pre_hooks/0` function in a Nebulex.Cache module to specify functions executed before cache actions. This example includes a pre-hook that can perform actions before a 'get' operation. ```elixir defmodule MyCache do use Nebulex.Cache, adapter: Nebulex.Adapters.Local def pre_hooks do pre_hook = fn (result, {_, :get, _} = call) -> # do your stuff ... (result, _) -> result end [pre_hook] end end ``` -------------------------------- ### Basic Plug.AccessLog Usage Source: https://hexdocs.pm/plug_accesslog/readme.html Integrate Plug.AccessLog into your plug pipeline or router to start logging requests. This example configures the log format to CLF and specifies the log file path. ```elixir defmodule AppRouter do use Plug.Router plug Plug.AccessLog, format: :clf, file: "/path/to/your/logs/access.log" plug :match plug :dispatch get "/hello" do send_resp(conn, 200, "world") end match _ do send_resp(conn, 404, "oops") end end ``` -------------------------------- ### Add Quickstart Provider to Supervision Tree Source: https://hexdocs.pm/plug_sigaws/PlugSigaws.html Register the `SigawsQuickStartProvider` as a worker in your application's supervision tree in `application.ex` to manage its lifecycle and credential reading. ```elixir use Application def start(_type, _args) do import Supervisor.Spec children = [ worker(SigawsQuickStartProvider, [[name: :sigaws_provider]]), # .... ] # .... Supervisor.start_link(children, opts) end ``` -------------------------------- ### Run Mix Session Setup Task Source: https://hexdocs.pm/plug_session_mnesia/Mix.Tasks.Session.Setup.html Execute the `mix session.setup` task to create the Mnesia table for session storage. ```bash mix session.setup ``` -------------------------------- ### Browser Localization Plug Configuration Source: https://hexdocs.pm/plug_locale/PlugLocale.Browser.html Example of configuring and using the PlugLocale.Browser plug in a Phoenix application. This setup detects the locale, integrates with Gettext, and persists the locale in a response cookie. ```elixir defmodule DemoWeb.PlugBrowserLocalization do use Plug.Builder plug PlugLocale.Browser, default_locale: "en", locales: ["en", "zh"], route_identifier: :locale, assign_key: :locale plug :put_locale def put_locale(conn, _opts) do if locale = conn.assigns[:locale] do # integrate with gettext Gettext.put_locale(locale) # persistent current locale into cookie PlugLocale.Browser.put_locale_resp_cookie( conn, locale, max_age: 365 * 24 * 60 * 60 ) else conn end end end ``` -------------------------------- ### Naive Redix Driver Wrapper Source: https://hexdocs.pm/plug_limit/index.html An example of a simple wrapper function for the Redix client to execute Redis commands. This function starts a Redix process, executes a command, and then stops the process. ```elixir def command(command, opts \ [timeout: 500]) do {:ok, pid} = Redix.start_link() Redix.command(pid, command, opts) :ok = Redix.stop(pid) end ``` -------------------------------- ### start/0 Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpApi.html Initializes the HTTP client. ```APIDOC ## start/0 ### Description Initializes the HTTP client. ### Parameters None. ``` -------------------------------- ### Basic Router Configuration with Error Handling Source: https://hexdocs.pm/plug/Plug.Router.html An example of a Plug.Router configuration that includes Plug.Debugger for development environments and Plug.ErrorHandler for custom error responses. It also defines a simple GET route. ```APIDOC ## Basic Router Configuration with Error Handling This example demonstrates setting up a Plug.Router with conditional debugging for development and custom error handling. ### Router Definition ```elixir defmodule AppRouter do use Plug.Router if Mix.env == :dev do use Plug.Debugger end use Plug.ErrorHandler plug :match plug :dispatch get "/hello" do send_resp(conn, 200, "world") end defp handle_errors(conn, %{kind: _kind, reason: _reason, stack: _stack}) do send_resp(conn, conn.status, "Something went wrong") end end ``` ### Explanation - `use Plug.Router`: Initializes the router. - `if Mix.env == :dev do use Plug.Debugger end`: Includes the debugger only in development. - `use Plug.ErrorHandler`: Enables custom error handling. - `plug :match` and `plug :dispatch`: Standard plugs for matching and dispatching routes. - `get "/hello" do ... end`: Defines a route for GET requests to `/hello`. - `handle_errors/2`: A private function to customize error responses. ``` -------------------------------- ### PlugWebhook Configuration Example Source: https://hexdocs.pm/plug_webhook/index.html Demonstrates a basic configuration for PlugWebhook, specifying the path, parser options, and the custom handler module. ```elixir plug PlugWebhook, handler: MyWebhookHandler, parser_opts: ... ``` -------------------------------- ### Pass Private Key as DER Binary Source: https://hexdocs.pm/plug/https.html Use the `:key` parameter to pass a private key directly as a DER binary, for example, from an environment variable. Note that reading environment variables in Mix config is limited to Mix-based application starts. ```elixir der = System.get_env("PRIVKEY") |> Base.decode64!() Plug.Cowboy.https MyApp.MyPlug, [], port: 8443, key: {:RSAPrivateKey, der}, #.... ``` -------------------------------- ### GET Request Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpJson.html Issues a GET request to the given URL. The `get!` variant raises an exception on failure. ```APIDOC ## GET ### Description Issues a GET request to the given URL. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the GET request to. - **headers** (list) - Optional - A list of headers to include in the request. Defaults to `[]`. - **options** (list) - Optional - Additional options for the request. Defaults to `[]`. ### Request Example ```elixir PlugCommon.HttpJson.get("http://example.com/resource") # or with headers PlugCommon.HttpJson.get("http://example.com/resource", [{"Accept", "application/json"}]) # To raise an exception on failure: PlugCommon.HttpJson.get!("http://example.com/resource") ``` ### Response #### Success Response (200 OK) Returns the response body. #### Response Example ```json { "data": "some data" } ``` ``` -------------------------------- ### start_link(opts \\ []) Source: https://hexdocs.pm/plug_cache/PlugCache.LocalCache.html Starts a supervision tree for the cache and returns `{:ok, pid}` or just `:ok` if no supervision is needed. ```APIDOC ## start_link(opts \\ []) ### Description Starts a supervision and return `{:ok, pid}` or just `:ok` if nothing needs to be done. ``` -------------------------------- ### start_link/1 Source: https://hexdocs.pm/plug_pagecache/Plug.PageCache.Adapter.ETS.html Starts the cache adapter. ```APIDOC ## start_link(opts) ### Description Starts the cache adapter. It will be registered under the id generated from its name by `Plug.PageCache.Config.cache_id/1`. ### Method start_link ### Parameters #### Path Parameters - **opts** (Keyword.t) - Required - Options for starting the adapter. ### Specs ``` start_link(Keyword.t) :: GenServer.on_start ``` ``` -------------------------------- ### HTTP GET Request Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpForm.html Issues a GET request to the specified URL. Use this for standard GET operations. ```elixir get(url, headers \\ [], options \\ []) ``` -------------------------------- ### Basic PlugSecex Setup Source: https://hexdocs.pm/plug_secex/PlugSecex.html Include PlugSecex in your browser pipeline for default security headers. ```elixir pipeline :browser do plug PlugSecex end ``` -------------------------------- ### Start Link Function Signature Source: https://hexdocs.pm/plug_amqp/Plug.Amqp.html Specifies the function signature for starting the AMQP module, returning a Supervisor start result. ```elixir @spec start_link(options()) :: Supervisor.on_start() ``` -------------------------------- ### Start Memcached Connection Source: https://hexdocs.pm/plug_session_memcached/Plug.Session.MEMCACHED.html This code starts a Memcached connection process. Ensure this is called on application start. The process name `:memcached_sessions` can be customized. ```elixir :mcd.start_link(:memcached_sessions, [] ) ``` -------------------------------- ### Plug.CloudFlare.init/1 Source: https://hexdocs.pm/plug_cloudflare_fb/Plug.CloudFlare.html Callback implementation for Plug.init/1. Initializes the plug with the provided options. ```APIDOC ## init/1 ### Description Callback implementation for Plug.init/1. Initializes the plug with the given options. ### Function Signature `init(options)` ### Parameters - `options` (keyword()) - Configuration options for the plug. ``` -------------------------------- ### get(client, id) Source: https://hexdocs.pm/pluggy_ai/Pluggy.Investments.html Gets an investment by ID. ```APIDOC ## get(client, id) ### Description Gets an investment by ID. ### Parameters #### Path Parameters - **client** (Pluggy.Client.t()) - Required - The Pluggy client instance. - **id** (String.t()) - Required - The ID of the investment to retrieve. ### Response #### Success Response (200) - **term** - The investment data or an error tuple. ### Response Example ```json {:ok, %{}} ``` ### Error Response - **Pluggy.Error.t()** - Represents an error during the API call. ``` -------------------------------- ### init(opts) Source: https://hexdocs.pm/plugs/Sugar.Plugs.HotCodeReload.html Callback implementation for `c:Plug.init/1`. This function is used to initialize the plug with given options. ```APIDOC ## init(opts) ### Description Callback implementation for `c:Plug.init/1`. ### Parameters #### Path Parameters - **opts** (any) - Required - Options to initialize the plug. ### Function Signature `init(opts)` ``` -------------------------------- ### get(client, id) Source: https://hexdocs.pm/pluggy_ai/Pluggy.Accounts.html Gets an account by ID. ```APIDOC ## get(client, id) ### Description Gets an account by ID. ### Parameters #### Path Parameters - **client** (Pluggy.Client.t()) - Required - The Pluggy client instance. - **id** (String.t()) - Required - The ID of the account to retrieve. ### Response #### Success Response - **term** - The account data or {:ok, term()} tuple. #### Error Response - **Pluggy.Error.t()** - The error details or {:error, Pluggy.Error.t()} tuple. ``` -------------------------------- ### start_link/1 Source: https://hexdocs.pm/plug_pubsub/PlugPubsub.Consumer.html Starts the consumer process. ```APIDOC ## start_link/1 ### Description Starts the consumer process. ### Function Signature start_link(_) ``` -------------------------------- ### get Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpForm.html Issues a GET request to the given url. ```APIDOC ## get(url, headers \\ [], options \\ []) ### Description Issues a GET request to the given url. ### Method GET ### Endpoint [url] ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the GET request to. #### Query Parameters None explicitly documented. #### Request Body None explicitly documented. ### Request Example ```json { "url": "/api/data/items", "headers": { "Accept": "application/json" }, "options": { "follow_redirect": true } } ``` ### Response #### Success Response (200) - **body** (any) - The response body from the server. #### Response Example ```json [ { "id": 1, "name": "Item 1" }, { "id": 2, "name": "Item 2" } ] ``` ``` -------------------------------- ### start/2 Source: https://hexdocs.pm/plug_cache/PlugCache.Application.html Callback implementation for `Application.start/2`. This function is called when an application is started and should initiate the application's top-level supervisor. ```APIDOC ## start/2 ### Description Called when an application is started using `Application.start/2` (and functions on top of that, such as `Application.ensure_started/2`). This function should start the top-level process of the application (which should be the top supervisor of the application’s supervision tree if the application follows the OTP design principles around supervision). `start_type` defines how the application is started: * `:normal` - used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another node and the application specification key `:start_phases` is `:undefined`. * `{:takeover, node}` - used if the application is distributed and is started on the current node because of a failover on the node `node`. * `{:failover, node}` - used if the application is distributed and is started on the current node because of a failover on node `node`, and the application specification key `:start_phases` is not `:undefined`. `start_args` are the arguments passed to the application in the `:mod` specification key (e.g., `mod: {MyApp, [:my_args]}`). This function should either return `{:ok, pid}` or `{:ok, pid, state}` if startup is successful. `pid` should be the PID of the top supervisor. `state` can be an arbitrary term, and if omitted will default to `[]`; if the application is later stopped, `state` is passed to the `stop/1` callback (see the documentation for the `c:stop/1` callback for more information). `use Application` provides no default implementation for the `start/2` callback. ### Parameters #### Path Parameters - **type** (atom | tuple) - Required - Defines how the application is started. Can be `:normal`, `{:takeover, node}`, or `{:failover, node}`. - **args** (term) - Required - Arguments passed to the application in the `:mod` specification key. ### Response #### Success Response - **{:ok, pid}** - If startup is successful, returns the PID of the top supervisor. - **{:ok, pid, state}** - If startup is successful, returns the PID of the top supervisor and the application state. ``` -------------------------------- ### Application Setup Source: https://hexdocs.pm/plug_rest/index.html Shows how to add the PlugRest router to your application's supervision tree. ```APIDOC ## Application Finally, add the Router to your supervision tree by editing `lib/my_app/application.ex`: ```elixir children = [ {Plug.Cowboy, scheme: :http, plug: MyApp.Router, options: [port: 4001]} ] ``` ``` -------------------------------- ### init(options) Source: https://hexdocs.pm/plug_checkup/PlugCheckup.html Initializes the PlugCheckup with given options. ```APIDOC ## init(options) ### Description Initializes the PlugCheckup with the specified options. ### Parameters #### Path Parameters - **options** (map) - Required - A map of options to configure the PlugCheckup. ### Request Example ```elixir PlugCheckup.init(%{path: "/health"}) ``` ### Response #### Success Response (any) - The initialized PlugCheckup configuration. ``` -------------------------------- ### start_link Source: https://hexdocs.pm/plug_auth/PlugAuth.CredentialStore.Agent.html Initializes and starts a new instance of the credentials store agent. ```APIDOC ## start_link() ### Description Starts a new credentials store. ### Response #### Success Response (200) - **agent_pid** (pid) - The process identifier of the started agent. ``` -------------------------------- ### TestTransport Example Source: https://hexdocs.pm/plug_proxy/PlugProxy.Transport.html An example implementation of a transport module using `:hackney`. ```APIDOC ## TestTransport ```elixir defmodule TestTransport do use PlugProxy.Transport import Plug.Conn, only: [read_body: 2] def write(conn, client, _opts) do case read_body(conn, []) do {:ok, body, conn} -> :hackney.send_body(client, body) :hackney.finish_send_body(client) conn {:more, body, conn} -> :hackney.send_body(client, body) write(conn, client, opts) end end def read(conn, client, _opts) do {:ok, status, headers, client} = :hackney.start_response(client) {:ok, body} = :hackney.body(client) %{conn | resp_headers: headers} |> send_resp(status, body) end end ``` ``` -------------------------------- ### start_link Source: https://hexdocs.pm/plug_metrics/PlugMetrics.MetricsServer.html Starts the MetricsServer supervisor. It takes a list of options as an argument. ```APIDOC ## start_link(options \\ []) ### Description Starts the MetricsServer supervisor with the provided options. ### Function Signature start_link(options \\ []) ### Parameters #### Path Parameters - **options** (list) - Optional - A list of options to configure the server. ``` -------------------------------- ### GraphQL Query Example Source: https://hexdocs.pm/plug_graphql/index.html Example of a GraphQL query to retrieve a greeting. ```json { "data": { "greeting": "Hello, world!" } } ``` -------------------------------- ### init(options) Source: https://hexdocs.pm/plug_paradox_auth/PlugParadoxAuth.GoogleAuthSet.html Initializes the Google authentication settings with provided options. ```APIDOC ## init(options) ### Description Initializes the Google authentication settings with provided options. ### Parameters #### Path Parameters - **options** (type) - Required - Description ``` -------------------------------- ### Start PlugAttack.Storage.Ets with Options Source: https://hexdocs.pm/plug_attack/PlugAttack.Storage.Ets.html Starts the ETS storage table and its cleaner process. The process is registered under the given name, and a public ETS table with that name is created. Options can be provided to configure the cleaning period. ```elixir PlugAttack.Storage.Ets.start_link(name, opts \\ []) ``` -------------------------------- ### Add sigaws_quickstart_provider to Dependencies Source: https://hexdocs.pm/plug_sigaws/PlugSigaws.html Include the `sigaws_quickstart_provider` in your project's dependencies in `mix.exs` to enable quickstart signature verification. ```elixir defp deps do {:sigaws_quickstart_provider, "~> 0.1"} end ``` -------------------------------- ### Install PlugCanonicalHost Source: https://hexdocs.pm/plug_canonical_host/readme.html Add the plug_canonical_host dependency to your mix.exs file to install the package. ```elixir defp deps do [ {:plug_canonical_host, "~> 2.0"} ] end ``` -------------------------------- ### PlugXForwardedProto.init/1 Source: https://hexdocs.pm/plug_x_forwarded_proto/PlugXForwardedProto.html Callback implementation for `Plug.init/1`. This function is used to initialize the plug with given options. ```APIDOC ## PlugXForwardedProto.init/1 ### Description Callback implementation for `Plug.init/1`. ### Function Signature `init(opts)` ### Parameters - **opts**: Options for initializing the plug. ``` -------------------------------- ### init(opts \\ []) Source: https://hexdocs.pm/plug_response_replace/PlugResponseReplace.html Callback implementation for Plug.init/1. This function is used to initialize the plug with given options. ```APIDOC ## init(opts \\ []) ### Description Callback implementation for `Plug.init/1`. This function is used to initialize the plug with given options. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### get!(client, id) Source: https://hexdocs.pm/pluggy_ai/Pluggy.Investments.html Gets an investment by ID, raising an error if retrieval fails. ```APIDOC ## get!(client, id) ### Description Gets an investment by ID. This function will raise an error if the investment cannot be retrieved. ### Parameters #### Path Parameters - **client** (Pluggy.Client.t()) - Required - The Pluggy client instance. - **id** (String.t()) - Required - The ID of the investment to retrieve. ### Response #### Success Response (200) - **term** - The investment data. ### Response Example ```json %{}} ``` ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_debug_logger/PlugDebugLogger.html Callback implementation for `Plug.init/1`. ```APIDOC ## init/1 ### Description Initializes the PlugDebugLogger with the provided options. ### Callback Callback implementation for `Plug.init/1`. ### Function Signature `init(opts)` ### Parameters * `opts` - The options for initializing the plug. ``` -------------------------------- ### get!(client, id) Source: https://hexdocs.pm/pluggy_ai/Pluggy.Accounts.html Gets an account by ID and raises an error if retrieval fails. ```APIDOC ## get!(client, id) ### Description Gets an account by ID and raises an error if retrieval fails. ### Parameters #### Path Parameters - **client** (Pluggy.Client.t()) - Required - The Pluggy client instance. - **id** (String.t()) - Required - The ID of the account to retrieve. ### Response #### Success Response - **term** - The account data. ``` -------------------------------- ### get! Source: https://hexdocs.pm/plug_http_client/PlugCommon.HttpForm.html Issues a GET request to the given url, raising an exception in case of failure. ```APIDOC ## get!(url, headers \\ [], options \\ []) ### Description Issues a GET request to the given url, raising an exception in case of failure. ### Method GET ### Endpoint [url] ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the GET request to. #### Query Parameters None explicitly documented. #### Request Body None explicitly documented. ### Request Example ```json { "url": "/api/data/items", "headers": { "Accept": "application/json" }, "options": { "follow_redirect": true } } ``` ### Response #### Success Response (200) - **body** (any) - The response body from the server. #### Response Example ```json [ { "id": 1, "name": "Item 1" }, { "id": 2, "name": "Item 2" } ] ``` #### Error Response - **exception** (any) - An exception is raised if the request fails. ``` -------------------------------- ### start_link() Source: https://hexdocs.pm/plug_response_cache/PlugResponseCache.Stores.Ets.html Starts the ETS store GenServer process. ```APIDOC ## start_link() ### Description Starts the ETS store GenServer process. This function is typically used within a supervision tree. ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_rails_cookie_session_store/PlugRailsCookieSessionStore-function-init.html Callback implementation for `Plug.Session.Store.init/1`. ```APIDOC ## init(opts) ### Description Callback implementation for `Plug.Session.Store.init/1`. ### Parameters #### Path Parameters - **opts** (any) - Required - Options for initializing the session store. ``` -------------------------------- ### HTTP Method: GET Source: https://hexdocs.pm/plug/Plug.Router.html Dispatches to the specified path only if the incoming request method is GET. ```APIDOC ## GET ### Description Dispatches to the path only if the request is a GET request. ### Method GET ### Endpoint [path] ### Parameters See `match/3` for more examples. ``` -------------------------------- ### init(options \\ []) Source: https://hexdocs.pm/plug_metrics/PlugMetrics.Queries.html Callback implementation for `Plug.init/1`. This function is used to initialize the Plug module with given options. ```APIDOC ## init(options \\ []) ### Description Callback implementation for `Plug.init/1`. ### Parameters * **options** - A keyword list of options for initialization. Defaults to an empty list. ### Returns An initialized module or configuration. ``` -------------------------------- ### Fetch dependencies Source: https://hexdocs.pm/plug_assign/readme.html Fetch and install the project dependencies using mix. ```bash $ mix deps.get ``` -------------------------------- ### get!(client, id, opts) Source: https://hexdocs.pm/pluggy_ai/Pluggy.Connectors.html Gets a connector by ID, raising an error if retrieval fails. ```APIDOC ## get!(client, id, opts) ### Description Gets a connector by ID, raising an error if retrieval fails. ### Parameters #### Path Parameters - **client** (Pluggy.Client.t()) - The Pluggy client instance. - **id** (integer()) - The unique identifier of the connector. - **opts** (keyword()) - Optional arguments. See Options below. ### Options * `:health_details` - Include health check details ### Response #### Success Response - `map()` - A map containing the connector details. ``` -------------------------------- ### Resource Macro with Plug Options Source: https://hexdocs.pm/plug_rest/PlugRest.Router.html This example demonstrates how to pass options to the Plug module when defining a resource route. ```elixir resource "/pages/:page", PageResource, [p: 1] ``` -------------------------------- ### Start Stateful Decoder Source: https://hexdocs.pm/plug/Plug.Conn.Query.html Starts a stateful decoder. Use `decode_each/2` and `decode_done/2` to decode and complete. ```elixir @spec decode_init() :: decoder() ``` -------------------------------- ### User Resource Example Source: https://hexdocs.pm/plug_rest/PlugRest.Resource.html An example of a UserResource module implementing the necessary callbacks for a RESTful resource. ```APIDOC ## MyApp.UserResource ### Description Implements RESTful resource handling for user data. ### Callbacks - `init/2`: Initializes the resource state. - `allowed_methods/2`: Defines the HTTP methods allowed for this resource. - `resource_exists/2`: Checks if the resource exists and retrieves its state. - `content_types_provided/2`: Specifies the content types the resource can provide. - `to_html/2`: Generates an HTML representation of the resource. ### Example Implementation ```elixir defmodule MyApp.UserResource do use PlugRest.Resource def init(conn, state) do {:ok, conn, state} end def allowed_methods(conn, state) do {["GET"], conn, state} end def resource_exists(%{params: params} = conn, _state) username = params["username"] # Look up user state = %{name: "John Doe", username: username} {true, conn, state} end def content_types_provided(conn, state) do {[{"text/html", :to_html}], conn, state} end def to_html(conn, %{name: name} = state) do {"
Hello, #{name}
", conn, state} end end ``` ``` -------------------------------- ### init/1 Source: https://hexdocs.pm/plug_ip_whitelist/Plug.IpWhitelist.HerokuRemoteIp.html Initializes the plug with options. This plug does not accept any options. ```APIDOC ## init/1 ### Description Initialize the plug with options (there are none) ### Function Signature ```elixir init(options) :: any() ``` ``` -------------------------------- ### Call PluggyElixir.hello/0 Source: https://hexdocs.pm/pluggy_elixir/PluggyElixir-function-hello.html Demonstrates how to call the `hello/0` function and its expected output. ```elixir iex> PluggyElixir.hello() :world ``` -------------------------------- ### Function Plug Example Source: https://hexdocs.pm/plug/Plug.html An example of a function plug that sets the response content type to JSON. ```APIDOC ## Examples Here's an example of a function plug: ``` def json_header_plug(conn, _opts) do Plug.Conn.put_resp_content_type(conn, "application/json") end ``` ``` -------------------------------- ### Installation in mix.exs Source: https://hexdocs.pm/plug_shopify_jwt/PlugShopifyEmbeddedJWTAuth.html Add the plug_shopify_jwt package to your project's dependencies in the mix.exs file to install it. ```elixir def deps do [ {:plug_shopify_jwt, "~> 0.1.0"} ] end ``` -------------------------------- ### Plug.IpWhitelist.HerokuRemoteIp Init Function Source: https://hexdocs.pm/plug_ip_whitelist/Plug.IpWhitelist.HerokuRemoteIp.html This function initializes the plug. It accepts options but currently has none defined. ```elixir init(options) ```