Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gleam-lang/plug
🔌 A Gleam HTTP service adapter for the Plug web application interface
https://github.com/gleam-lang/plug
elixir gleam http
Last synced: 3 months ago
JSON representation
🔌 A Gleam HTTP service adapter for the Plug web application interface
- Host: GitHub
- URL: https://github.com/gleam-lang/plug
- Owner: gleam-lang
- License: apache-2.0
- Created: 2020-08-16T15:21:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-08-27T19:31:09.000Z (almost 4 years ago)
- Last Synced: 2024-03-14T19:53:56.990Z (4 months ago)
- Topics: elixir, gleam, http
- Language: Elixir
- Homepage: https://hexdocs.pm/gleam_plug
- Size: 16.6 KB
- Stars: 31
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Lists
- awesome-gleam - gleam-lang/plug - A Gleam HTTP service adapter for the Plug web application interface. (HTTP servers)
README
# Gleam Plug! 🔌
A Gleam HTTP service adapter for the Plug web application interface.
## Usage
Define a Gleam HTTP service
```rust
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
```elixir
defmodule MyPlug do
def init(options) do
options
enddef 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.```elixir
defmodule MyAppWeb.UserController do
use MyAppWeb, :controllerdef show(conn, params) do
conn
|> GleamPlug.call_service(params, &:my_gleam_module.service/1)
end
end
```## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `gleam_plug` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:gleam_plug, "~> 0.1.0"}
]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/gleam_plug](https://hexdocs.pm/gleam_plug).