Skip to content

Commit

Permalink
add named alias Webapp.Server.HTTP.Response
Browse files Browse the repository at this point in the history
  • Loading branch information
choonkeat committed Jul 25, 2021
1 parent 20a2b36 commit ebdf5fb
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ This difference can be put into good use when we handle `updateFromClient` or `u
- [encoders & decoders are auto-generated](https://github.com/choonkeat/elm-auto-encoder-decoder) in `src/Protocol/Auto.elm` ; also see [gotchas regarding imported types](https://github.com/choonkeat/elm-auto-encoder-decoder#dont-be-alarmed-with-i-cannot-find--variable-compiler-errors)
- we're using `elm-auto-encoder-decoder` in `elm-webapp` only for convenience; you can switch it out for your own encoders & decoders. BUT if you continue using `elm-auto-encoder-decoder`, don't use them anywhere else (e.g. as encoder to save in db, exposed as part of your external api, etc...). Main reason being that the serialized format could change future releases of `elm-auto-encoder-decoder` and thus MUST NOT be relied on.

## How do I...

- Support OAuth login? See https://github.com/choonkeat/elm-webapp-oauth-example#readme

## License

Copyright © 2021 Chew Choon Keat
Expand Down
15 changes: 9 additions & 6 deletions bin/elm-webapp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "choonkeat/elm-webapp",
"summary": "Small framework for writing fullstack HTTP webapp in Elm. Try `npx elm-webapp`",
"license": "MIT",
"version": "1.0.2",
"version": "2.0.0",
"exposed-modules": [
"Webapp.Server.HTTP",
"Webapp.Server",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"elm-webapp": "./bin/elm-webapp"
},
"name": "elm-webapp",
"version": "1.2.2",
"version": "2.0.0",
"description": "cli to initialize an elm-webapp app",
"main": "bin/elm-webapp",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Application.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Http
import Json.Decode
import Json.Encode
import Platform exposing (Task)
import Task
import Protocol
import Protocol.Auto
import Task
import Url
import Webapp.Client

Expand Down
2 changes: 1 addition & 1 deletion src/Document.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Http
import Json.Decode
import Json.Encode
import Platform exposing (Task)
import Task
import Protocol
import Protocol.Auto
import Task
import Url
import Webapp.Client

Expand Down
2 changes: 1 addition & 1 deletion src/Element.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Http
import Json.Decode
import Json.Encode
import Platform exposing (Task)
import Task
import Protocol
import Protocol.Auto
import Task
import Url
import Webapp.Client

Expand Down
19 changes: 4 additions & 15 deletions src/Webapp/Server.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import Dict exposing (Dict)
import Json.Decode
import Json.Encode
import Platform exposing (Task)
import Protocol
import Task
import Time
import Protocol
import Url
import Webapp.Server.HTTP exposing (Body, Headers, Method, Request, StatusCode(..), bodyOf, headersOf, methodOf, pathOf, urlOf)
import Webapp.Server.HTTP exposing (Body, Headers, Method, Request, Response, StatusCode(..), bodyOf, headersOf, methodOf, pathOf, urlOf)
import Webapp.Server.Websocket
import Webapp.Shared

Expand Down Expand Up @@ -81,11 +81,7 @@ type alias PlatformWorker flags model msg =
writeResponse :
(Json.Encode.Value -> Cmd msg)
-> Request
->
{ statusCode : StatusCode
, headers : List ( String, Json.Encode.Value )
, body : String
}
-> Response
-> Cmd msg
writeResponse onHttpResponse request { statusCode, body, headers } =
let
Expand Down Expand Up @@ -138,14 +134,7 @@ writeWebsocketMessage writeWs connection key body =
-}
type alias Ports msg x serverMsg =
{ writeResponse :
Request
->
{ statusCode : StatusCode
, headers : List ( String, Json.Encode.Value )
, body : String
}
-> Cmd (FrameworkMsg msg x serverMsg)
{ writeResponse : Request -> Response -> Cmd (FrameworkMsg msg x serverMsg)
, onHttpRequest : (Json.Encode.Value -> FrameworkMsg msg x serverMsg) -> Sub (FrameworkMsg msg x serverMsg)
, onWebsocketEvent : (Json.Encode.Value -> FrameworkMsg msg x serverMsg) -> Sub (FrameworkMsg msg x serverMsg)
, writeWebsocketMessage : Webapp.Server.Websocket.Connection -> Webapp.Server.Websocket.Key -> String -> Cmd (FrameworkMsg msg x serverMsg)
Expand Down
12 changes: 10 additions & 2 deletions src/Webapp/Server/HTTP.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Webapp.Server.HTTP exposing
( Body, Headers, Method(..), Request, StatusCode(..), Url
( Body, Headers, Method(..), Request, Response, StatusCode(..), Url
, bodyOf, headersOf, methodFromString, methodOf, methodString, pathOf, statusInt, urlOf
)

Expand All @@ -8,7 +8,7 @@ module Webapp.Server.HTTP exposing
# Definition
@docs Body, Headers, Method, Request, StatusCode, Url
@docs Body, Headers, Method, Request, Response, StatusCode, Url
# Common Helpers
Expand Down Expand Up @@ -122,6 +122,14 @@ type alias Request =
Json.Decode.Value


{-| -}
type alias Response =
{ statusCode : StatusCode
, headers : List ( String, Json.Encode.Value )
, body : String
}


{-| Alias for opaque Json.Encode.Value
-}
type alias Headers =
Expand Down
4 changes: 2 additions & 2 deletions templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ src/Protocol/Auto.elm: src/Protocol.elm
#
WATCHING=false elm-auto-encoder-decoder src/Protocol.elm

build/Server.js: src/**/*.elm
build/Server.js: src/*.elm src/**/*.elm
elm make src/Server.elm --output build/Server.js

public/assets/client.js: src/**/*.elm
public/assets/client.js: src/*.elm src/**/*.elm
elm make src/Client.elm --output public/assets/client.js

#
Expand Down

0 comments on commit ebdf5fb

Please sign in to comment.