← all modules

Sky.Http.Server

Sky.Http.Server
  Sky.Http.Server — HTTP server (Layer 3 Sky source).

Types
  type alias Request = { method : String , path : String , body : String , headers : Dict String String , params : Dict String String , query : Dict String String , cookies : Dict String String , remoteAddr : String }
  type alias Response = { status : Int , body : String , headers : Dict String String , contentType : String }
  type alias Handler = Request -> Task Error Response
  type Route
  type Server
  type Cookie

Values
  addCookie : Cookie -> Response -> Response
      `addCookie c resp` — attach a cookie built with `cookie` (defaults
  any : String -> (Request -> Task Error Response) -> Route
      `any path handler` — register a route that matches any HTTP
  api : String -> (Request -> Task Error Response) -> Route
      `api spec handler` — register an API route that bypasses
  body : Request -> String
      The raw request body.
  cookie : String -> String -> Cookie
      `cookie name value` — build a default cookie (Path=/, HttpOnly,
  delete : String -> (Request -> Task Error Response) -> Route
      `delete path handler` — register a DELETE route.
  formValue : String -> Request -> String
      `formValue name req` — read a parsed form field.  Unlike `param` /
  get : String -> (Request -> Task Error Response) -> Route
      `get path handler` — register a GET route.
  getCookie : String -> Request -> Maybe String
      `getCookie name req` — read a cookie value.
  header : String -> Request -> Maybe String
      `header name req` — read a request header (case-insensitive).
  html : String -> Response
      `html body` — build a 200 OK `text/html` response.  CSRF
  json : String -> Response
      `json body` — build a 200 OK `application/json` response.
  listen : Int -> List Route -> Task Error ()
      `listen port routes` — bind the server.  The returned Task
  method : Request -> String
      The request method (`"GET"`, `"POST"`, …).  Equivalent to the
  param : String -> Request -> Maybe String
      `param name req` — read a URL path parameter
  path : Request -> String
      The request path (`"/users/42"`), without the query string.
  post : String -> (Request -> Task Error Response) -> Route
      `post path handler` — register a POST route.
  put : String -> (Request -> Task Error Response) -> Route
      `put path handler` — register a PUT route.
  queryParam : String -> Request -> Maybe String
      `queryParam name req` — read a `?key=value`-style query string
  redirect : String -> Response
      `redirect url` — build a 302 response that points the client
  rpc : String -> (Request -> Task Error Response) -> Route
      `rpc spec handler` — register a browser RPC route that
  setConsoleAuth : (Request -> Task Error (Maybe a)) -> Task Error ()
      `setConsoleAuth check` — let the app's own users open the Sky Console
  static : String -> String -> Route
      `static urlPrefix diskPath` — serve files from `diskPath` at
  staticNotFound : String -> String -> Handler -> Route
      `staticNotFound urlPrefix diskPath handler` — like [`static`], but a
  text : String -> Response
      `text body` — build a 200 OK `text/plain` response.
  use : (Handler -> Handler) -> List Route -> List Route
      `use middleware routes` — wrap the handler of every route in the list
  withCookie : String -> String -> String -> Response -> Response
      `withCookie name value attrs resp` — attach a cookie with an explicit
  withHeader : String -> String -> Response -> Response
      `withHeader name value resp` — add (or override) a response
  withStatus : Int -> Response -> Response
      `withStatus code resp` — override the status code.