http-pony: A type unsafe http library

[ bsd3, library, network ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7
Change log ChangeLog.md
Dependencies base (>=4.8 && <5), bytestring (>=0.10), exceptions (>=0.8.3), network (>=2.6), pipes (>=4.1), pipes-network (>=0.6), pipes-safe (>=2.2), transformers (>=0.4) [details]
License BSD-3-Clause
Author Jinjing Wang
Maintainer nfjinjing@gmail.com
Category Network
Home page https://github.com/nfjinjing/http-pony
Uploaded by JinjingWang at 2017-05-27T13:49:42Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 5285 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-05-27 [all 1 reports]

Readme for http-pony-0.1.0.7

[back to package description]

Teaser

Let's write a hello world app.

{-# LANGUAGE OverloadedStrings #-}

module Hello where

import Pipes (yield)

hello _ = pure (("HTTP/1.1 200 OK", []), yield "hello world\n")

Note, we are not importing any interface!

If we take a closer look at the type of hello:

Prelude Hello> :t hello 
hello
  :: (Applicative f, Data.String.IsString a, Data.String.IsString t,
      Monad m) =>
    t2 -> f ((t, [t1]), Pipes.Internal.Proxy x' x () a m ())

This is a pure app!

Shall we run it?

{-# LANGUAGE OverloadedStrings #-}

module RunHello where

import Hello (hello)
import Network.HTTP.Pony.Serve (run)
import Network.HTTP.Pony.Transformer.HTTP (http)
import Pipes.Safe (runSafeT)

main :: IO ()
main = (runSafeT . run "localhost" "8080" . http) hello

Test it:

# the above files are mirrored in `./test`
runghc -isrc -itest test/RunHello.hs

# open another terminal
curl localhost:8080 -i

# output:

> HTTP/1.1 200 OK
>
> hello world

wow ~

Exercise: write a tcp cat