Packages
mist
0.1.3
6.0.3
6.0.2
6.0.1
6.0.0
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
5.0.0-rc1
4.0.7
4.0.6
4.0.5
4.0.4
4.0.3
4.0.2
4.0.1
4.0.0
3.0.0
2.0.0
1.2.0
1.1.0
1.0.0
1.0.0-rc3
1.0.0-rc2
1.0.0-rc1
0.17.0
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.2
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.3
a misty Gleam web server
Current section
Files
Jump to
Current section
Files
README.md
# mist
A (hopefully) nice, basic gleam web server
## Installation
This package can be added to your Gleam project:
```sh
gleam add mist
```
and its documentation can be found at <https://hexdocs.pm/mist>.
## Examples
See the `examples/` folder for the full sample(s).
#### HTTP Hello World
```gleam
pub fn ok(_msg: HandlerMessage, sock: Socket) -> actor.Next(Socket) {
assert Ok(resp) =
"hello, world!"
|> bit_string.from_string
|> http_response(200, _)
|> bit_string.to_string
resp
|> charlist.from_string
|> send(sock, _)
actor.Stop(process.Normal)
}
```
#### Full HTTP echo handler
```gleam
pub fn handler(req: Request(BitString)) -> Response(BitString) {
response.new(200)
|> response.set_body(req.body)
}
pub fn main() {
assert Ok(socket) = mist.listen(8000, [])
try _ = mist.start_acceptor_pool(socket, make_handler(handler), 10)
Ok(erlang.sleep_forever())
}
```
## Notes
This is still very rough. There are no tests, and as noted above you can't just
send where you implement it.
In some [not-very-scientific benchmarking](https://gist.github.com/rawhat/11ab57ef8dde4170304adc01c8c05a99), it seemed to do roughly as well as
ThousandIsland. I am just using that as a reference point, certainly not trying
to draw any comparisons any time soon!