Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gleam-lang/cowboy
🤠A Gleam HTTP service adapter for the Cowboy web server
https://github.com/gleam-lang/cowboy
erlang gleam http
Last synced: about 1 month ago
JSON representation
🤠A Gleam HTTP service adapter for the Cowboy web server
- Host: GitHub
- URL: https://github.com/gleam-lang/cowboy
- Owner: gleam-lang
- License: apache-2.0
- Created: 2020-08-16T12:50:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T20:28:22.000Z (9 months ago)
- Last Synced: 2024-03-20T21:32:17.171Z (9 months ago)
- Topics: erlang, gleam, http
- Language: Gleam
- Homepage:
- Size: 55.7 KB
- Stars: 50
- Watchers: 4
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Gleam Cowboy! ðŸ¤
A Gleam HTTP service adapter for the [Cowboy][cowboy] web server.
You may want to consider using the [Mist][mist] web server instead as it has
better performance, features type safe websockets, and is written entirely in
Gleam. It is also supported by the [Wisp][wisp] web framework.## Installation
```sh
gleam add gleam_cowboy
``````gleam
import gleam/erlang/process
import gleam/http/cowboy
import gleam/http/response.{type Response}
import gleam/http/request.{type Request}
import gleam/bytes_builder.{type BytesBuilder}// Define a HTTP service
//
pub fn my_service(request: Request(t)) -> Response(BytesBuilder) {
let body = bytes_builder.from_string("Hello, world!")response.new(200)
|> response.prepend_header("made-with", "Gleam")
|> response.set_body(body)
}// Start it on port 3000!
//
pub fn main() {
cowboy.start(my_service, on_port: 3000)
process.sleep_forever()
}
```## Limitations
Cowboy does not support duplicate HTTP headers so any duplicates specified by
the Gleam HTTP service will not be sent to the client.[cowboy]: https://github.com/ninenines/cowboy
[mist]: https://github.com/rawhat/mist
[wisp]: https://github.com/lpil/wisp