Git Product home page Git Product logo

plug's Introduction

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.

plug's People

Contributors

lpil avatar krendil avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.