Hello all! I’m looking for some feedback on the Gleam HTTP library API. If you’re a twitter users please vote here: https://twitter.com/louispilfold/status/1282272545622970368
If not, reply with a comment, thank you
Hello all! I’m looking for some feedback on the Gleam HTTP library API. If you’re a twitter users please vote here: https://twitter.com/louispilfold/status/1282272545622970368
If not, reply with a comment, thank you
I prefer the one http module approach, because I personally can’t think of too many times where you’d want to use http requests but not responses. You’d only want requests with no responses when making a http call, and I think it’s a lot more likely that people will use Gleam as an http server rather than an http client. Just my 0.02c, take with a grain of salt, etc.
Re:reload in phoenix
I got some sort of reconpiliation/reloading going by adding :gleam as a reloadable compiler in my endpoint config, but currently it recompiles on every http request. https://hexdocs.pm/phoenix/Phoenix.CodeReloader.html
Not solved but made some progress. Thanks to @michaeljones post https://dev.to/contact-stack/adding-a-custom-watcher-to-phoenix-1e10
I added a chokidar watcher that runs gleam build
, which I in turn add to my watchers in the Endpoint configuration in my dev.exs
. However the compiled code is not reloaded in the phoenix app it appears.
Note that CodeReloader that I mentioned previously is a plug, and as far as I understand from the docs it’s by design that it reloads code on each request.
Gleam v0.11.0-rc1 is out. Please upgrade your projects and give it a try
https://github.com/gleam-lang/gleam/releases/tag/v0.11.0-rc1
Here’s a random dumb question. Have you (or anybody else in the team) made a thin wrapper around Phoenix in Gleam?
Not a dumb question at all!
Currently Gleam has a HTTP library and a Plug adapter that will allow you to call Gleam HTTP service modules from Plug applications (such as Phoenix). I’ll be writing more about this with the comining release but you may be able to get something going with the READMEs + hexdocs for now:
Here’s what usage might look like:
Define a Gleam service module
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)
}
Call it from Elixir
defmodule MyAppWeb.UserController do
use MyAppWeb, :controller
def show(conn, params) do
conn
|> GleamPlug.call_service(params, &:my_gleam_module.service/1)
end
end
This is exciting! I was checking in on Midas from time to time but the repository seems quite quiet which is perfectly understandable. I need to keep an eye on the wider gleam repositories it seems
Indeed it is. Most of the first version of midas found a home in other places. Quick summary if you like
Midas is definitely not off my radar, just I think it will now more usefully be the conventions that bring together the things listed above
Gleam v0.11.0 is out! As per usual I’ve made a post giving an overview of what’s new. Check it out here -> https://lpil.uk/blog/gleam-v0.11-released/
One thing I think people will find interesting here is the support for embedding Gleam HTTP services inside Elixir Plug apps.
I’m really happy to see that 0.11.0 includes a more elegant way of updating records!
Good work everyone involved
Hey folks, I’ve written a little Elixir site to pull together the Github activity feeds from various Gleam repositories and show them all on one timeline. It is basic but quite useful for scanning recent activity.
https://dashboard.michaelpjones.co.uk/gleam
There is also a /elm which covers various elm community repositories. There repos are hard coded but the code is open source so you can easily suggest more and I can deploy it quite easily. Also welcome to improve the layout or highlight some things more. I reduced the visual display of the commits as they get quite noisy and I’ve just added a button to hide all comments as they can be overwhelming too. There might be plenty of other improvements though. I’ve also no expert designer. I’ve attempted to make it work on mobile and I’ve enjoyed using Tailwind on it. Not used it for that much before.
I think it might be quite interesting to have a version that can also include notable tweets or blog posts or other events from a community which could then be categorised into various levels so that you could see a high level year by year overview or a more detailed catch up of the last few months or a very thorough update on the last week.
Is there an LSP project yet?
No, not yet. It is on the backlog though.
Hi, can i specify subtype as function argument type or return type, list element type ?I tried something like example below, but i got a compilation error
pub opaque type Cart {
Empty
NonEmpty
}
pub fn new() -> Empty {
todo
}
pub fn checkout(cart: NonEmpty) -> Int {
todo
}
I don’t know anything about Gleam but can you really use only one type from discriminated union like that because it looks wrong? Are you sure checkout
functions type shouldn’t be type Cart
instead of NonEmpty
?
Hi @arturs678! Thanks for trying out Gleam!
Gleam doesn’t have any form of subtyping, so Empty
and NonEmpty
only have a single type, and that type is Cart
. Empty
and NonEmpty
are values, not types.
As @wanton7 says the type annotations will need to be changed to Cart
and then the code you’ve given will compile.
pub opaque type Cart {
Empty
NonEmpty
}
pub fn new() -> Cart {
Empty
}
pub fn checkout(cart: Cart) -> Int {
todo
}
Quinn Wilton’s ElixirConf talk is up!
ElixirConf 2020 - Type-Safe LiveView with Gleam - Quinn Wilton
Maybe you actually want to do something like this:
pub opaque type Cart {
EmptyCart
NonEmptyCart(info: CartInfo)
}
pub opaque type CartContents {
CartContents(
products: List(Product)
// And maybe other fields
)
}
Now you can have functions that require a filled cart as input or output work directly on CartContents
, and have functions that should also work for empty carts use the Cart
wrapper type.
Hi everyone!
In order to make the Gleam community a bit more accessible we’re moving from IRC to Discord. It’s easier to use, saves chat history for people to read back over, and has anti-harassment features (which hopefully we won’t need), so overall it’s a big improvement.
Please join using this link here -> https://discord.gg/Fm8Pwmy
Thanks!