All Projects → gleam-lang → plug

gleam-lang / plug

Licence: Apache-2.0 license
🔌 A Gleam HTTP service adapter for the Plug web application interface

Programming Languages

elixir
2628 projects
rust
11053 projects

Labels

Projects that are alternatives of or similar to plug

template-gleam-javascript
🧃 A template for trying out Gleam compiled to JavaScript
Stars: ✭ 22 (-12%)
Mutual labels:  gleam
Gleam
⭐️ A friendly language for building type-safe, scalable systems!
Stars: ✭ 3,463 (+13752%)
Mutual labels:  gleam
setup-gleam
👷‍♀️ Gleam on GitHub Actions
Stars: ✭ 16 (-36%)
Mutual labels:  gleam
vscode-gleam
📟 Gleam support for VS Code
Stars: ✭ 34 (+36%)
Mutual labels:  gleam
Synapses
A group of neural-network libraries for functional and mainstream languages
Stars: ✭ 63 (+152%)
Mutual labels:  gleam
example-echo-server
🔗 An example Gleam web application
Stars: ✭ 59 (+136%)
Mutual labels:  gleam
gleam compile
Tiny hex package to make the development experience of using gleam in elixir (and especially phoenix projects) better.
Stars: ✭ 29 (+16%)
Mutual labels:  gleam
cowboy
🤠 A Gleam HTTP service adapter for the Cowboy web server
Stars: ✭ 24 (-4%)
Mutual labels:  gleam
gleam-mode
🐙 Gleam support for Emacs
Stars: ✭ 30 (+20%)
Mutual labels:  gleam
mix gleam
⚗️ Build Gleam code with mix
Stars: ✭ 84 (+236%)
Mutual labels:  gleam
gleam decode
Transform Erlang or Elixir data into Gleam data
Stars: ✭ 25 (+0%)
Mutual labels:  gleam
stdlib
🎁 Gleam's standard library
Stars: ✭ 153 (+512%)
Mutual labels:  gleam
otp
📫 Fault tolerant multicore programs with actors
Stars: ✭ 169 (+576%)
Mutual labels:  gleam
website
🏡 Gleam's website and guide
Stars: ✭ 35 (+40%)
Mutual labels:  gleam

Gleam Plug! 🔌

A Gleam HTTP service adapter for the Plug web application interface.

Usage

Define a Gleam HTTP service

import gleam/http
import gleam/bit_builder.{BitBuilder}

pub fn service(req: http.Request(BitBuilder)) {
  http.response(200)
  |> http.prepend_resp_header("made-with", "Gleam")
  |> http.set_resp_body(req.body)
}

And then call it from an Elixir Plug application

defmodule MyPlug do
  def init(options) do
    options
  end

  def call(conn, body) do
    conn
    |> GleamPlug.call_service(body, &:my_gleam_module.service/1)
  end
end

Phoenix controllers are Plugs and so Gleam services can be called from them in the same way.

defmodule MyAppWeb.UserController do
  use MyAppWeb, :controller

  def show(conn, params) do
    conn
    |> GleamPlug.call_service(params, &:my_gleam_module.service/1)
  end
end

Installation

If available in Hex, the package can be installed by adding gleam_plug to your list of dependencies in mix.exs:

def deps do
  [
    {:gleam_plug, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/gleam_plug.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].