Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roc-lang/basic-webserver
A basic webserver in Roc
https://github.com/roc-lang/basic-webserver
roc-lang
Last synced: about 2 months ago
JSON representation
A basic webserver in Roc
- Host: GitHub
- URL: https://github.com/roc-lang/basic-webserver
- Owner: roc-lang
- License: upl-1.0
- Created: 2023-09-19T16:19:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-30T17:18:26.000Z (5 months ago)
- Last Synced: 2024-05-01T11:35:52.845Z (5 months ago)
- Topics: roc-lang
- Language: Roc
- Homepage: https://roc-lang.github.io/basic-webserver/
- Size: 479 KB
- Stars: 43
- Watchers: 9
- Forks: 10
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- roc-awesome - roc-lang/basic-webserver
README
:book: docs: [main branch](https://roc-lang.github.io/basic-webserver/)
:eyes: examples: [0.4](https://github.com/roc-lang/basic-webserver/tree/0.4.0/examples), [0.3](https://github.com/roc-lang/basic-webserver/tree/0.3.0/examples), [0.2](https://github.com/roc-lang/basic-webserver/tree/0.2.0/examples), [0.1](https://github.com/roc-lang/basic-webserver/tree/0.1/examples)
:warning: On linux `--linker=legacy` is necessary for this package because of [this Roc issue](https://github.com/roc-lang/roc/issues/3609).
# Basic Web Server for [Roc](https://www.roc-lang.org/)
A webserver [platform](https://github.com/roc-lang/roc/wiki/Roc-concepts-explained#platform) with a simple interface.
:racing_car: basic-webserver uses Rust's high-performance [hyper](https://hyper.rs) and [tokio](https://tokio.rs) libraries to execute your Roc function on incoming requests.
## Example
Run this example server with `$ roc helloweb.roc` (on linux, add `--linker=legacy`) and go to `http://localhost:8000` in your browser.
```roc
app [main] {
pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.6.0/LQS_Avcf8ogi1SqwmnytRD4SMYiZ4UcRCZwmAjj1RNY.tar.gz"
}import pf.Stdout
import pf.Task exposing [Task]
import pf.Http exposing [Request, Response]
import pf.Utcmain : Request -> Task Response []
main = \req -># Log request date, method and url
date = Utc.now! |> Utc.toIso8601Str
Stdout.line! "$(date) $(Http.methodToStr req.method) $(req.url)"Task.ok { status: 200, headers: [], body: Str.toUtf8 "Hello, world!\n" }
```
## Contributing
If you'd like to contribute, check out our [group chat](https://roc.zulipchat.com) and let us know what you're thinking, we're friendly!
## Developing / Building Locally
If you have cloned this repository and want to run the examples without using a packaged release (...tar.br), you will need to build the platform first by running `roc build.roc`. Run examples with `roc examples/hello.roc` (on linux, add `--linker=legacy`).