Coder Social home page Coder Social logo

jluzny / basic-webserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roc-lang/basic-webserver

0.0 0.0 0.0 489 KB

A basic webserver in Roc

Home Page: https://roc-lang.github.io/basic-webserver/

License: Universal Permissive License v1.0

Shell 1.57% C 0.04% Rust 26.51% Nix 1.12% Roc 70.76%

basic-webserver's Introduction

๐Ÿ“– docs: main branch

๐Ÿ‘€ examples: 0.4, 0.3, 0.2, 0.1

Basic Web Server for Roc

A webserver platform with a simple interface.

Write a function which takes a Http.Request, perform I/O like fetching content or reading environment variables, and return a Http.Response. It's that easy!

Behind the scenes, basic-webserver uses Rust's high-performance hyper and tokio libraries to execute your Roc function on incoming requests.

โš ๏ธ On linux --linker=legacy is necessary for this package because of this Roc issue.

Example

Hello world webserver:

app "helloweb"
    packages { pf: "https://github.com/roc-lang/basic-webserver/releases/download/0.4.0/iAiYpbs5zdVB75golcg_YMtgexN3e2fwhsYPLPCeGzk.tar.br" }
    imports [
        pf.Stdout,
        pf.Task.{ Task },
        pf.Http.{ Request, Response },
        pf.Utc,
    ]
    provides [main] to pf

main : Request -> Task Response []
main = \req ->

    # Log request date, method and url
    date <- Utc.now |> Task.map Utc.toIso8601Str |> Task.await
    {} <- Stdout.line "$(date) $(Http.methodToStr req.method) $(req.url)" |> Task.await

    Task.ok { status: 200, headers: [], body: Str.toUtf8 "<b>Hello, world!</b>\n" }

Run this example server with $ roc run helloweb.roc --linker=legacy and go to http://localhost:8000 in your browser.

Contributing

If you'd like to contribute, check out our group chat and let us know what you're thinking, we're friendly!

Steps to re-generate glue

Run the following from the repository root directory.

  1. Run bash platform/glue-gen.sh
  2. Manually fix any issues with glue generated code in platform/glue-manual/*.rs, this is a temporary workaround and should not be needed in future

basic-webserver's People

Contributors

lukewilliamboswell avatar anton-4 avatar rtfeldman avatar imclerran avatar bhansconnect avatar agu-z avatar rmailaender avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.