# elm-http-server

> A puny module for putting together HTTP-servers using Elm

Latest version **10.0.0** (published 2017-10-05) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install elm-http-server
pnpm add elm-http-server
yarn add elm-http-server
bun add elm-http-server
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2017-10-05 |
| First published | 2017-08-23 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | asger nielsen |
| Maintainers | opvasger |
| Keywords | elm, node, http, server |

## Links

- npm: https://www.npmjs.com/package/elm-http-server
- Repository: https://github.com/opvasger/elm-http-server
- Homepage: https://github.com/opvasger/elm-http-server#readme
- Issues: https://github.com/opvasger/elm-http-server/issues
- npm.io page: https://npm.io/package/elm-http-server

## Dependencies (1)

- [xhr2](https://npm.io/package/xhr2.md) 0.1.4

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 10.0.0 (latest) — 2017-10-05
- 9.0.0 — 2017-10-02
- 8.0.0 — 2017-09-24
- 7.0.0 — 2017-09-19
- 6.0.0 — 2017-09-19
- 5.0.0 — 2017-09-19
- 4.0.0 — 2017-09-18
- 3.0.0 — 2017-09-08
- 2.1.0 — 2017-08-30
- 2.0.0 — 2017-08-23
- 1.0.0 — 2017-08-23
- 0.2.0 — 2017-08-23
- 0.1.0 — 2017-08-23

## README

# Elm Http Server
A puny module for putting together HTTP-servers using Elm

## Warning
Elm (along with the Elm architecture) is designed for browser-applications; This project in experimental attempt to embed the architecture inside a small Node.js Http-server program. Taking the unreasonable performance implications aside, it is fun to experience Elm as a shared language between client and server with all of it's nice properties for continuous improvement and modification. Enjoy! :)

## Usage
The module is distributed through NPM:

`npm install -S elm-http-server`

Go to `elm-package.json` and expose the internal Elm-code from the module:


    {       ...
        "source-directories": [
            ...
            "node_modules/elm-http-server/source"
        ],
        ...
    }

Examples of usage can be found in the `examples` sub-directory.

## Features
- Utility-modules for working with Http-Request/Response on the server
- Emulation for XmlHttpRequest to enable `elm-lang/http` to run on the server
- A tiny API to hook Elm's `Platform.program` into `Http.createServer` in Node.JS

## JavaScript Interface
in Node.js, assuming an Elm module named `Main` compiled to `main.elm.js` in the same directory, the API can be used as such:

    var Ehs = require("elm-http-server")
    var Http = require("http")
    var App = require("./main.elm.js")
    
    var PORT = 3000

    var ID_GEN_SIZE = 420

    var onRequest = Ehs.createRequestListener(App.Main.worker(), ID_GEN_SIZE)
    
    var onStart = function () {
        console.log("server started at http://localhost:" + PORT)
    }

    Http.createServer()
    .on("request", onRequest)
    .listen(PORT, onStart)

Importing `elm-http-server` automatically exposes `XmlHttpRequest` globally to enable usage of `elm-lang/http` in the Elm-modules on the server.

## Elm Interface
There is a couple of tiny modules for Elm, written to facilitate some basic server-logic.

### Server.Request
    type alias Request =
    { id : Id
    , method : Method
    , headers : Dict String String
    , url : String
    , body : Maybe String
    }
###
    type Method
        = Get
        | Put
        | Post
        | Delete
        | Other String
###
    listen : (Result String Request -> msg) -> Sub msg

### Server.Response
    html : Request.Id -> Status -> Server.Html.Document -> Response
###
    text : Request.Id -> Status -> String -> Response
###
    json : Request.Id -> Status -> Json.Encode.Value -> Response
###
    empty : Request.Id -> Status -> Response
###
    send : Response -> Cmd msg

### Server.Response.Header
    type alias Header = ( String, String )
###
    contentType : String -> Header
###
    textContent : Header
###
    htmlContent : Header
###
    jsonContent : Header

### Server.Response.Status
    type alias Status =
    { code : Int
    , message : String
    }
###
    ok : Status
###
    badRequest : Status
###
    unauthorized : Status
###
    notFound : Status
###
    internalError : Status

### Server.Html
    document : String -> String -> Document
###
    toString : Document -> String

---
_Source: https://npm.io/package/elm-http-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
